When using "Dynamically populated Select Options" x-model is empty on first render #4546
Replies: 4 comments
-
|
This issue has been converted to a discussion as we are now using discussions to track bugs and ideas. |
Beta Was this translation helpful? Give feedback.
-
|
Why would it? You never set anything to the model. the select does not emit a change event when it gets new options added. Could you not set the x-model color to red ahead of time? |
Beta Was this translation helpful? Give feedback.
-
|
I know I could do that, currently I am using But if you ask me, it would be more elegant, if alpine does this under the hood, upon init. |
Beta Was this translation helpful? Give feedback.
-
|
For anyone struggling with cascading selects not updating x-model, here is a "set and forget" solution. It uses a custom directive to watch for DOM changes in the options and forces a refresh. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When using "Dynamically populated Select Options"
x-modelis empty on first render.Expected behaviour: The first value in the list (
Red) should be loaded intox-model.Dynamically populated Select Options
https://alpinejs.dev/directives/model#dynamically-populated-select-options
Also check: #1872
Beta Was this translation helpful? Give feedback.
All reactions