Default value for select
I want to have the default value for a select not only pre-selected in the frontend, but also when saving. Currently, the validation throws an error that a value has to be chosen, even though the select (with placeholder disabled) shows the value that should be default.
An example:
10 Replies
are you editing a form you have added this field too by any chance?
yes
That will be why since the field is now empty. IF you create a new record, does it work as normal?
ah yes, you're right. On create, it works as expected, but not on edit
but why is the field empty? shouldn't it use the value I have set on the model/db?
currency? The field name is "curency"..
The field is empty because you pass in an empty variable on the mounting of the data as we empty the dataset then push in the new data. What you should do, manipulate the data if it is null/empty then return a default value.
thanks, fixed the name and suddenly it works π
Magic
I know exactly how that feels! Hahaha