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
Fix for #13514.Set selectedIdx to 0 if a 'wrong' value is set as dropdown-list value #1191
Changes from 1 commit
13860db
63174e0
df7daa3
8805f64
646b498
8fd6479
1d7d830
bb3eb30
c293a60
a2f7906
72ede71
30e2e4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,6 +280,12 @@ jQuery.extend({ | |
|
||
if ( !values.length ) { | ||
elem.selectedIndex = -1; | ||
} else { | ||
// IE 9 doesn't select a dropdown-list's first option | ||
// when value doesnt match with one of its options' value | ||
if ( elem.selectedIndex < 0 ) { | ||
elem.selectedIndex = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work correctly when
and proceed from there, making sure to add thorough unit tests for both select-one and select-multiple. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This issue is not occurring to select-multiple. Do you mean that the code has to be changed so that calling val() with a 'wrong' option value(s) on select-multiple will also select the first option? Currently no option will be selected when passing a 'wrong' value to val() in case of select-multiple. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Observe the change in behavior from introducing this code: http://jsfiddle.net/wuM8f/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My latest changes: http://jsfiddle.net/aVjyH/1/ to preserve the current behavior when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right of course; we slip it in there because a select-multiple with nothing selected can follow the single-get var optionSet,
values = jQuery.makeArray( value ),
options = elem.options,
index = elem.selectedIndex,
// Keep as a variable only if overall gzip size is smaller
// than using elem.type !== "select-one" directly in an if condition
one = elem.type === "select-one"; and try using the loop body instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following your advice, I've come up with this change. However, I don't use the |
||
} | ||
} | ||
return values; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be
Support: IE9
. is IE7/8/10 also affected?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I haven't had a chance to check the issue on these ie versions. Anyway, I will try to check it out today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, you also meant the comment needs to be changed to Suport: IE9 ..., right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staabm: this issue doesnt affect IE7/8, I havent had a chance to test it on IE10 though.