diff options
author | rwldrn <waldron.rick@gmail.com> | 2011-05-20 11:03:33 -0400 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-05-20 11:03:33 -0400 |
commit | f82b9dddc498efdfbcd0978f8ba3e1da3b48eff3 (patch) | |
tree | 3238e4c108d250c7bd288a5c4f36a80902f78937 | |
parent | a1545b5079f4a25fb1dbe7cdfce76fff7a73afe3 (diff) | |
download | jquery-f82b9dddc498efdfbcd0978f8ba3e1da3b48eff3.tar.gz jquery-f82b9dddc498efdfbcd0978f8ba3e1da3b48eff3.zip |
Landing pull request 382. Adds support for number values (meter,progress); Fixes #9319.
More Details:
- https://github.com/jquery/jquery/pull/382
- http://bugs.jquery.com/ticket/9319
-rw-r--r-- | src/attributes.js | 8 | ||||
-rw-r--r-- | test/unit/attributes.js | 24 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/attributes.js b/src/attributes.js index c239dd7f3..5396a90e5 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -165,7 +165,13 @@ jQuery.fn.extend({ return ret; } - return (elem.value || "").replace(rreturn, ""); + ret = elem.value; + + return typeof ret === "string" ? + // handle most common string cases + ret.replace(rreturn, "") : + // handle cases where value is null/undef or number + ret == null ? "" : ret; } return undefined; diff --git a/test/unit/attributes.js b/test/unit/attributes.js index c4ed7d30f..56c398e5c 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -611,6 +611,30 @@ test("val()", function() { equals( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" ); }); +if ( "value" in document.createElement("meter") && + "value" in document.createElement("progress") ) { + + test("val() respects numbers without exception (Bug #9319)", function() { + + expect(4); + + var $meter = jQuery("<meter min='0' max='10' value='5.6'></meter>"), + $progress = jQuery("<progress max='10' value='1.5'></progress>"); + + try { + equal( typeof $meter.val(), "number", "meter, returns a number and does not throw exception" ); + equal( $meter.val(), $meter[0].value, "meter, api matches host and does not throw exception" ); + + equal( typeof $progress.val(), "number", "progress, returns a number and does not throw exception" ); + equal( $progress.val(), $progress[0].value, "progress, api matches host and does not throw exception" ); + + } catch(e) {} + + $meter.remove(); + $progress.remove(); + }); +} + var testVal = function(valueObj) { expect(8); |