]> source.dussan.org Git - jquery.git/commitdiff
Attributes: Use the option val hook in select val hook and simplify it 1901/head
authorMichał Gołębiowski <m.goleb@gmail.com>
Thu, 4 Dec 2014 13:43:35 +0000 (14:43 +0100)
committerMichał Gołębiowski <m.goleb@gmail.com>
Mon, 8 Dec 2014 21:39:58 +0000 (22:39 +0100)
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

src/attributes/val.js
test/unit/attributes.js

index f67afb156efaa5467688d0fefd17a80b9e24a145..c5e8c63f42c17d16f888f9e34105ce66ec6f9c33 100644 (file)
@@ -74,12 +74,9 @@ jQuery.extend({
        valHooks: {
                option: {
                        get: function( elem ) {
-                               var val = jQuery.find.attr( elem, "value" );
-                               return val != null ?
-                                       val :
-                                       // Support: IE10-11+
-                                       // option.text throws exceptions (#14686, #14858)
-                                       jQuery.trim( jQuery.text( elem ) );
+                               // Support: IE<11
+                               // option.value not trimmed (#14858)
+                               return jQuery.trim( elem.value );
                        }
                },
                select: {
@@ -130,7 +127,8 @@ jQuery.extend({
 
                                while ( 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;
                                        }
                                }
index 69be6abe0646b662d6b59f8a77c7599001b18776..c1f77371853fbd6729964310b2988a722d8bc0ab 100644 (file)
@@ -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() {
        expect ( 3 );