Skip to content

Commit

Permalink
Landing pull request 382. Adds support for number values (meter,progr…
Browse files Browse the repository at this point in the history
…ess); Fixes #9319.

More Details:
 - jquery#382
 - http://bugs.jquery.com/ticket/9319
  • Loading branch information
rwaldron authored and timmywil committed May 20, 2011
1 parent a1545b5 commit f82b9dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/attributes.js
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/attributes.js
Expand Up @@ -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);

Expand Down

0 comments on commit f82b9dd

Please sign in to comment.