Is it somehow possible to set the select value to null if not visible

I am trying to set the select value to null if the field is not visible in the form. What I have so far.
Toggle::make('customize_compounding')->label('Customize Compounding')->live()->columnSpan(['default' => 2]),
Group::make([
Select::make('compound_interval')
->enum(CompoundInterval::class)
->options(CompoundInterval::class)
->default(CompoundInterval::OneMonth->value)
->selectablePlaceholder(false)
->columnSpan(['default' => 2, 'sm' => 1]),
])->visible(fn (\Filament\Forms\Get $get): bool => $get('customize_compounding'))
Toggle::make('customize_compounding')->label('Customize Compounding')->live()->columnSpan(['default' => 2]),
Group::make([
Select::make('compound_interval')
->enum(CompoundInterval::class)
->options(CompoundInterval::class)
->default(CompoundInterval::OneMonth->value)
->selectablePlaceholder(false)
->columnSpan(['default' => 2, 'sm' => 1]),
])->visible(fn (\Filament\Forms\Get $get): bool => $get('customize_compounding'))
I don't know how to make that work. Someone has an idea?
6 Replies
krekas
krekas7mo ago
Try setting default value when it is visible
Houssem
Houssem7mo ago
If you're using admin panel you can set it in the Edit record of your resource by using mutateFormDataBeforeSave method.
Dennis Koch
Dennis Koch7mo ago
If the field is hidden, it's not included in the form request. So you need to manually reset it like Daniel explained
TheNastyPasty
TheNastyPastyOP7mo ago
The strange thing is I get an value if the field is hidden and I dont want this to happen. What I mean if toggle is 0 I get the default value of compound interval
krekas
krekas7mo ago
maybe dont dehrydate when you dont need it
TheNastyPasty
TheNastyPastyOP7mo ago
can't use ->dehydrate() on select Maybe I should check customize_compunding in the backend and not compound interval
Want results from more Discord servers?
Add your server