pinoooh
pinoooh
FFilament
Created by pinoooh on 12/6/2024 in #❓┊help
Post hidden fields to reset data
Hi there, I have a resource-form with multiple steps, and on top of each step is a toggle to "enable" some fields visually. If the toggle is enabled, the form-fields are displayed which contains all sorts of input: text, (multi)-select with relations, repeaters, etc. All of this works perfectly. Psuedo-form to give you an idea:
Step::make('step 1'))->schema([
Toggle::make('toggle_1')
->default(false)
->live(),

Group::make()
->visible(if_enabled('toggle_1'))
->schema([
TextInput->make('name');
]);
]);

Step::make('step 2'))->schema([
Toggle::make('toggle_2')
->default(false)
->live(),

Group::make()
->visible(if_enabled('toggle_2'))
->schema([
Select->make('relation.name')
->multiple();
]);
]);
Step::make('step 1'))->schema([
Toggle::make('toggle_1')
->default(false)
->live(),

Group::make()
->visible(if_enabled('toggle_1'))
->schema([
TextInput->make('name');
]);
]);

Step::make('step 2'))->schema([
Toggle::make('toggle_2')
->default(false)
->live(),

Group::make()
->visible(if_enabled('toggle_2'))
->schema([
Select->make('relation.name')
->multiple();
]);
]);
As said: all works perfectly! Now I want to "reset" all the input on a specific step if the toggle is disabled. In other words: I want to set the fields to null, delete relations etc if the toggle is off. I could do this "manually" using mutateFormDataBeforeSave for example (lots of if issets etc), but I would rather have the logic on the form itself to keep the logic grouped. Is this even possible? I tried making an extension of a group, which creates hidden fields but this does not work well. Is there another way to do this? Thanks in advance!
5 replies
FFilament
Created by pinoooh on 6/4/2024 in #❓┊help
default value when hidden()
I created a field that is only visible when a toggle is set (using visible()). This works fine, but when I update the field value AND toggle the field mentioned, the value of this field is not saved. I understand why this is the case: the field is not included in the post-data because it's not visible. Is there a way to set a "default"-value when the field is not visible? dehydrateStateUsing() does not seem to work (even with dehydratedWhenHidden()? I know I could use the lifecycle-hooks, or even model-events but I want to include it in the form (to keep it all together). Any ideas?
11 replies
FFilament
Created by pinoooh on 2/8/2024 in #❓┊help
Enum in TextEntry of InfoList
Hi, I have a model with an enum-property (cast) which I want to display in an infolist, but this gives me an Error:
TextEntry::make('model.enumProperty')
TextEntry::make('model.enumProperty')
this results in Object of class App\Enums\MyEnum could not be converted to string I don't mind converting the value e.g. using formatStateUsing on the TextEntry but the code already fails on the name. As a workaround I can do this, but this it's not very nice 🙂
TextEntry::make('model.created_at')
->formatStateUsing(static function (Model $model): string {
...
}
}
TextEntry::make('model.created_at')
->formatStateUsing(static function (Model $model): string {
...
}
}
Any idea?
6 replies