]> source.dussan.org Git - jquery.git/commitdiff
Fix setting value attributes on option elements. Fixes #9071.
authortimmywil <tim.willison@thisismedium.com>
Tue, 3 May 2011 18:48:36 +0000 (14:48 -0400)
committertimmywil <tim.willison@thisismedium.com>
Tue, 3 May 2011 18:48:36 +0000 (14:48 -0400)
src/attributes.js
test/unit/attributes.js

index 017a32da405bcb4130c347f46e441c99173b70a2..2da2e16397717d27a1ad0a27541ffa17b3a3179f 100644 (file)
@@ -199,7 +199,7 @@ jQuery.fn.extend({
                        hooks = jQuery.valHooks[ this.nodeName.toLowerCase() ] || jQuery.valHooks[ this.type ];
 
                        // If set returns undefined, fall back to normal setting
-                       if ( !hooks || ("set" in hooks && hooks.set( this, val, "value" ) === undefined) ) {
+                       if ( !hooks || !("set" in hooks) || hooks.set( this, val, "value" ) === undefined ) {
                                this.value = val;
                        }
                });
index 37e854d06946cbb51a4f9b364f44dfc92158b209..b1cfe3db2490ed86f01ae6552aec7a8b304e97a3 100644 (file)
@@ -447,7 +447,7 @@ test("removeProp(String)", function() {
 });
 
 test("val()", function() {
-       expect(25);
+       expect(26);
 
        document.getElementById("text1").value = "bla";
        equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
@@ -513,6 +513,8 @@ test("val()", function() {
        var $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
        equals( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
        equals( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" );
+       
+       equals( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" );
 });
 
 var testVal = function(valueObj) {