Prompt input via modal on save
Hi,
I have a status field on a form which is a
ToggleButton
populated by an enum. I would like to add some functionality so that when I save the form, if this field has changed to a specific option then a modal should appear and the user should enter a reason (which is just a text area).
I would like the reason to save into a different database table as the form I'm on because I'd like to save individual rows for each change so that I can report on all the changes later (rather than overwriting the reason each time).
I'm at a real loss of how to make this happen as I'm fairly new to filament.
I managed to make it overwrite the data on the same model but hiding / showing a field, but that's not what I want - I want a modal to popup on save. I also tried to add a relationship to a Group
but that is still a HasOne
where I would like a HasMany
.
Any ideas or pointers in the right direction would be much appreciated.
ThanksSolution:Jump to solution
You could register an action and trigger it in afterStateUpdated
```php
->registerActions([
Forms\Components\Actions\Action::make('reason')...
4 Replies
I'm wondering whether the easiest way would be to avoid using a modal completely. Just conditionally show a field and then save it to the relationship in the beforeSave method?
Solution
You could register an action and trigger it in afterStateUpdated
you need to add
live()
in the ToggleAmazing! This is exactly what I needed. Half the battle with learning Filament is knowing the best way to approach something - or at least what to search for in the docs.
Thanks π