When Select component has no options, save Select field as null #9833
Replies: 2 comments
-
If anyone would like to try this, follow the steps here |
Beta Was this translation helpful? Give feedback.
-
Same as here, but in my case a have a different situation. I have a dependant select, when editing a resource, if i change the country, the state option reload correctly but instead of 'Select a option', it comes with the first value selected, so i need to select the 'Select a option' field, and then select the corret option, otherwise the old value is submitted. |
Beta Was this translation helpful? Give feedback.
-
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
withinmutateFormDataBeforeSave(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?!Beta Was this translation helpful? Give feedback.
All reactions