Repository navigation
plugin/bound: reapply the select value when its options change - #77
Merged
Merged
Conversation
x-bound applied the bound value to a <select> when the value changed, and once when its deferred binding started, after x-for had rendered the initial options. Options that changed after that were not synced: when x-for items were loaded from an empty list, added, or changed their values, the select showed the first option while the property kept its value. Options inside an <optgroup> and <select multiple> were affected the same way. Observe the options and apply the bound value again whenever they change. The deferred start stays: when the property is null or undefined, it is initialized from the element, and before Alpine initializes the options that value is wrong, e.g. an option with :value="0" would give its text instead of 0.
📦 Bundle size comparison
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
x-boundapplied the bound value to a<select>when the value changed, and once when its deferred binding started, afterx-forhad rendered the initial options. Options that changed after that were not synced: whenx-foritems were loaded from an empty list, added, or changed their values, the select showed the first option while the property kept its value. Options inside an<optgroup>and<select multiple>were affected the same way.Observe the options and apply the bound value again whenever they change: options added or removed anywhere in the select, their
valueattributes, and their text. Alpine fixed the same case forx-modelin 3.16.0 (alpinejs/alpine#4769), observing only the select's direct children.The deferred start stays. When the property is
nullorundefined, it is initialized from the element, and before Alpine initializes the options that value is wrong: with<option :value="0">None</option>the property would get"None"instead of0.