Ask questionsWrong option selected on init (x-for usage in select)
There are some issues with which option is selected when select's options are generated with
x-for. See pen for demo.
Both selects should display "cucumbers" after the page loads and Alpine initiates component.
The select with a static option (after
x-for'd options) shows the static option as selected. Other one shows the first available option as selected.
See how selects get correct option selected when you cause any changes in component data. Maybe this issue can be solved by triggering a forced update after selects with
x-for'd options are rendered?
Answer questions hkan
Re-setting the same value in
$nextTick was the first thing I tried. It doesn't work. Binding
:selected seems to work.