Why Select field does not save as null when no options exist i.e. only placeholder
I have a problem where I have a Select with dynamic options generated within a repeater.
If the Select has options and the user has saved the form with an option selected, the data is submitted to the json field in the database - as expected.
If the Select no longer has any options i.e. an empty state with the placeholder "Select an option", this should save a null value back to the database but it doesn't.
It still has the data attached that existed before, even though the Select is empty.
I can prove this by dumping $data within mutateFormDataBeforeSave(array $data), the field has the data from before and I am very confused as to why.
It is my understanding $data includes client side submitted values only and does not fetch anything from the database at this stage.
So why would it be fetching the previous data from the Select that no longer exists?
Steps:
Before:
User selects 'water', then value is saved to database in json e.g. "type": "water"
After:
User cannot select anything, submits form and in the $data array, "water" still exists within the submitted data. How?!
7 Replies
I have set up a demo repo here if anyone would like to have a go at recreating:
https://github.com/joshembling/filament-select-bug
I got the same issue 😭 don't know what it is doing that...
I am also having the same issue, any update for a fix?
Here is a related github issue: https://github.com/filamentphp/filament/issues/7715
GitHub
Setting select to nullable not working on save ^3.0-stable (v3.0.19...
Package filament/filament Package Version ^3.0-stable (v3.0.19) Laravel Version 10.18.0 Livewire Version v3 PHP Version PHP 8.2 Problem description Check the Dsicussion #7712 Hello, this is what i ...
Is the column fillable in your model? It says that in the issue..
Hi, Yes issue persists with Unguard and fillable. The above example provided by Josh has unguard enabled.
i've solved by setting my field as fillable (similar situation)