mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Attributes: Use the option val hook in select val hook and simplify it
The hook is still defined; not using it could cause issues in IE<11. Also, IE10 no longer throws when value not set but it still doesn't trim the value. IE11 has all those issues fixed; support comments are updated. Fixes gh-1902 Closes gh-1901
This commit is contained in:
parent
dd596ccf72
commit
f6302b0b53
@ -74,12 +74,9 @@ jQuery.extend({
|
|||||||
valHooks: {
|
valHooks: {
|
||||||
option: {
|
option: {
|
||||||
get: function( elem ) {
|
get: function( elem ) {
|
||||||
var val = jQuery.find.attr( elem, "value" );
|
// Support: IE<11
|
||||||
return val != null ?
|
// option.value not trimmed (#14858)
|
||||||
val :
|
return jQuery.trim( elem.value );
|
||||||
// Support: IE10-11+
|
|
||||||
// option.text throws exceptions (#14686, #14858)
|
|
||||||
jQuery.trim( jQuery.text( elem ) );
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
@ -130,7 +127,8 @@ jQuery.extend({
|
|||||||
|
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
option = options[ i ];
|
option = options[ i ];
|
||||||
if ( (option.selected = jQuery.inArray( option.value, values ) >= 0) ) {
|
if ( (option.selected =
|
||||||
|
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0) ) {
|
||||||
optionSet = true;
|
optionSet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1461,6 +1461,11 @@ test( "should not throw at $(option).val() (#14686)", 1, function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test( "option value not trimmed when setting via parent select", function() {
|
||||||
|
expect( 1 );
|
||||||
|
equal( jQuery( "<select><option> 2</option></select>" ).val( "2" ).val(), "2" );
|
||||||
|
});
|
||||||
|
|
||||||
test( "Insignificant white space returned for $(option).val() (#14858)", function() {
|
test( "Insignificant white space returned for $(option).val() (#14858)", function() {
|
||||||
expect ( 3 );
|
expect ( 3 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user