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:
Repeater::make('maintenance')
->schema([
Select::make('type')
->label('Maintenance Type')
->options(['water' => 'Water', 'filter' => 'Filter'])
]);
Repeater::make('maintenance')
->schema([
Select::make('type')
->label('Maintenance Type')
->options(['water' => 'Water', 'filter' => 'Filter'])
]);
User selects 'water', then value is saved to database in json e.g. "type": "water" After:
Repeater::make('maintenance')
->schema([
Select::make('type')
->label('Maintenance Type')
->options([])
]);
Repeater::make('maintenance')
->schema([
Select::make('type')
->label('Maintenance Type')
->options([])
]);
User cannot select anything, submits form and in the $data array, "water" still exists within the submitted data. How?!
7 Replies
Josh777
Josh7778mo ago
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
FL
FL8mo ago
I got the same issue 😭 don't know what it is doing that...
ohgeesy
ohgeesy8mo ago
I am also having the same issue, any update for a fix?
ohgeesy
ohgeesy8mo ago
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 ...
Andrew Wallo
Andrew Wallo8mo ago
Is the column fillable in your model? It says that in the issue..
ohgeesy
ohgeesy8mo ago
Hi, Yes issue persists with Unguard and fillable. The above example provided by Josh has unguard enabled.
Soundmit
Soundmit8mo ago
i've solved by setting my field as fillable (similar situation)
Want results from more Discord servers?
Add your server
More Posts