Core: Update elementValue method to deal with type="number" fields

The HTML5 draft defines, for type="number" inputs: "The value
sanitization algorithm is as follows: If the value of the element is not
a valid floating-point number, then set it to the empty string instead."
If the constraint validation considers the input invalid, return false
as the value, instead of the empty string, for the number and digit
methods to output their messages.

This would break in browsers that support type="number", but not the
constraint validation API. I don't know of any existing browser where
that applies.

Fixes #858
Fixes #922
Closes #1093
This commit is contained in:
Jamie R. Rytlewski
2014-04-25 11:34:52 -04:00
committed by Jörn Zaefferer
parent 104e8efceb
commit d09a5ee199
2 changed files with 50 additions and 0 deletions

View File

@@ -554,6 +554,8 @@ $.extend($.validator, {
if ( type === "radio" || type === "checkbox" ) {
return $("input[name='" + element.name + "']:checked").val();
} else if ( type === "number" && typeof element.validity !== "undefined" ) {
return element.validity.badInput ? false : $(element).val();
}
val = $element.val();