]> source.dussan.org Git - jquery.git/commitdiff
Attributes: Simplify the option val hook; backport a test from master
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:51:55 +0000 (22:51 +0100)
The hook is still defined; not using it could cause issues in IE<11.
Backport the test from the master branch.

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.

(cherry-picked from f6302b0b53d61dfe1adbfaf6612be5cbced5bbc1)

Fixes gh-1902
Closes gh-1901

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

index d9dd836cb86848efd34cc38aa6d686e54c30abe0..6adf8e2d2a048be497ab5976e08ace6b2a9f1113 100644 (file)
@@ -72,12 +72,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: {
index 55bdfffbd3eea223d3d61da589eca3adabe2414f..1e9c2fee220f1481a83063087982af8865157013 100644 (file)
@@ -1459,6 +1459,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 );