Hi,
I'm amazed the optgroup tag is already implemented using an array in an array
But what I can't find is how to set the previous value?
for example for an input it's easy:
I don't understand what you mean.
If you don't provide a pre-select value, your browser is going the select the first option in the dropdown, this is by design.
If you don't want that, add a dummy value as first option to the values array, as it's done in the documentation (this is what's meant by 'none').
I usually add a '0' => 'none selected' as first option, where '0' is whatever the default value of your database column is.
Well thats the problem there is no default in my database.
They need to pick a choice. But if I create a dummy I suppose that dummy is also selectable.
If it's selectable it's possible to save it, I dont want that
Capture the dummy value in your validation or in your controller code, and return a "please select a value" message.
You should validate all input before saving it into the database anyway.