Skip to content

Commit 7f21cb8

Browse files
author
John Wesely
committed
fix file upload bug in branch 4.x
1 parent 994d1e3 commit 7f21cb8

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

src/Livewire/FilamentForm/Show.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public function getFormSchema(): array
110110
->live();
111111
}
112112

113+
if ($fieldData->type === FilamentFieldTypeEnum::RICH_EDITOR) {
114+
$filamentField = $filamentField->disableToolbarButtons(['attachFiles']);
115+
}
116+
113117
array_push($schema, $filamentField);
114118
}
115119

tests/ShowRichEditorTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
use Filament\Forms\Components\RichEditor;
4+
use Illuminate\Support\Collection;
5+
use Tapp\FilamentFormBuilder\Enums\FilamentFieldTypeEnum;
6+
use Tapp\FilamentFormBuilder\Livewire\FilamentForm\Show;
7+
use Tapp\FilamentFormBuilder\Models\FilamentForm;
8+
use Tapp\FilamentFormBuilder\Models\FilamentFormField;
9+
10+
it('disables the attachFiles toolbar button for rich editor fields in the form schema', function () {
11+
$field = new FilamentFormField;
12+
$field->setRawAttributes([
13+
'id' => 1,
14+
'filament_form_id' => 1,
15+
'type' => 'RICH_EDITOR',
16+
'label' => 'Content',
17+
'required' => false,
18+
'hint' => null,
19+
'rules' => null,
20+
'options' => null,
21+
'schema' => null,
22+
'step' => null,
23+
'order' => 1,
24+
]);
25+
26+
$form = new FilamentForm;
27+
$form->setRawAttributes([
28+
'id' => 1,
29+
'name' => 'Test Form',
30+
'description' => null,
31+
'redirect_url' => null,
32+
'permit_guest_entries' => false,
33+
'is_wizard' => false,
34+
]);
35+
$form->setRelation('filamentFormFields', Collection::make([$field]));
36+
37+
$show = new Show;
38+
$show->filamentForm = $form;
39+
40+
$schema = $show->getFormSchema();
41+
42+
expect($schema)->toHaveCount(1);
43+
44+
$richEditor = $schema[0];
45+
expect($richEditor)->toBeInstanceOf(RichEditor::class);
46+
47+
// In Filament v5, disableToolbarButtons() queues a modification rather than
48+
// immediately filtering the array. Inspect the queue via reflection to confirm
49+
// that attachFiles has been disabled without needing a mounted container.
50+
$modifications = (new \ReflectionProperty($richEditor, 'toolbarButtonsModifications'))->getValue($richEditor);
51+
expect($modifications)->toContain(['type' => 'disable', 'buttons' => ['attachFiles']]);
52+
});
53+
54+
it('does not affect non-rich-editor fields', function () {
55+
$field = new FilamentFormField;
56+
$field->setRawAttributes([
57+
'id' => 2,
58+
'filament_form_id' => 1,
59+
'type' => 'TEXT',
60+
'label' => 'Name',
61+
'required' => false,
62+
'hint' => null,
63+
'rules' => null,
64+
'options' => null,
65+
'schema' => null,
66+
'step' => null,
67+
'order' => 1,
68+
]);
69+
70+
$form = new FilamentForm;
71+
$form->setRawAttributes([
72+
'id' => 1,
73+
'name' => 'Test Form',
74+
'description' => null,
75+
'redirect_url' => null,
76+
'permit_guest_entries' => false,
77+
'is_wizard' => false,
78+
]);
79+
$form->setRelation('filamentFormFields', Collection::make([$field]));
80+
81+
$show = new Show;
82+
$show->filamentForm = $form;
83+
84+
$schema = $show->getFormSchema();
85+
86+
expect($schema)->toHaveCount(1);
87+
expect($schema[0])->not->toBeInstanceOf(RichEditor::class);
88+
});

0 commit comments

Comments
 (0)