F
Filament4mo ago
Toni

Empty field on condition

I have the following schema:
Toggle::make('notify_unlock')
->label(__('form.labels.notifyUnlock'))
->live()
->columnSpan(1),
Select::make('notify_unlock_mail_template_id')
->label(__('form.labels.notifyUnlockMailTemplate'))
->options(MailTemplate::query()->where('is_published','=',1)->pluck('name', 'id'))
->required()
->visible(fn(Get $get) => $get('notify_unlock'))
->columnSpan(2)
Toggle::make('notify_unlock')
->label(__('form.labels.notifyUnlock'))
->live()
->columnSpan(1),
Select::make('notify_unlock_mail_template_id')
->label(__('form.labels.notifyUnlockMailTemplate'))
->options(MailTemplate::query()->where('is_published','=',1)->pluck('name', 'id'))
->required()
->visible(fn(Get $get) => $get('notify_unlock'))
->columnSpan(2)
I want to empty the select box if the toggle button notify_unlock is false. As far I tried: - dehydrateStateUsing - beforeStateDehydrated None of them set the value of the Selectbox to null. Kind regards, Toni
Solution:
```php Toggle::make('notify_unlock') ->label(__('form.labels.notifyUnlock')) ->live() ->columnSpan(1)...
Jump to solution
2 Replies
Solution
toeknee
toeknee4mo ago
Toggle::make('notify_unlock')
->label(__('form.labels.notifyUnlock'))
->live()
->columnSpan(1)
->afterStateUpdated(fn($state, $set) => !$state ? $set('notify_unlock_mail_template_id', null) : '',
Toggle::make('notify_unlock')
->label(__('form.labels.notifyUnlock'))
->live()
->columnSpan(1)
->afterStateUpdated(fn($state, $set) => !$state ? $set('notify_unlock_mail_template_id', null) : '',
Toni
ToniOP4mo ago
I hope you hear the bump of my head onto the table. Thank you so much!
Want results from more Discord servers?
Add your server