-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
selected="selected" not working as expected with 4.0.1 #3990
Comments
Fiddle displaying behaviour: http://jsfiddle.net/harhoo/9k7o9per/6 |
At this point, after seeing all of the tickets, this is definitely a bug. |
I'm also encountering similar issue. |
+1 |
This adds a broken test that demonstrates the issue seen in #3990 where existing selected options are being reset once Select2 is initialized. This issue cannot be reproduced on the options page [1] because the issue only appear to happen if the selected option is not the first one in the list of possible options. [1]: https://select2.github.io/examples.html#data-array
This should have been fixed by d1ed0a5. |
This adds a broken test that demonstrates the issue seen in select2#3990 where existing selected options are being reset once Select2 is initialized. This issue cannot be reproduced on the options page [1] because the issue only appear to happen if the selected option is not the first one in the list of possible options. [1]: https://select2.github.io/examples.html#data-array
Hello, this fix seems to just be the failing test -- I am still experiencing the issue in 4.0.6, did I miss something? I am adding an initial option tag with a select that uses ajax. Thank you! |
for me, Any idea what i could do ? |
A very simple way to tackle this problem is : //Step1: Here assuming id of your selectbox is my_id, so this will add selected attribute to 1st option $('#my_id option').eq(0).prop('selected',true); //Step2: Now reinitialize your select box //This will work, if you haven't initialized selectbox $('#my_id').select2(); or //This will work, if you have initialized selectbox earlier, so destroy it first and initialise it $('#my_id').select2('destroy').select2(); |
Have just run into an issue where an upgrade to 4.0.1 has changed functionality over 4.0.0. Not sure if this is expected behaviour. Previously this worked:
where date_options is [{"id":99,"text":"Some Text","type_id":1},{"id":100,"text":"Existing hoice","type_id":5}] etc.
Now, under 4.0.1, the No Choice option is always selected (doesn't matter whether it's first or second in the list).
Downgrading back to 4.0.0 fixes the issue.
The text was updated successfully, but these errors were encountered: