Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

required attribute fix for non-html5 browsers. Fixes #301 #356

Closed
wants to merge 1 commit into from

2 participants

This page is out of date. Refresh to see the latest.
Showing with 12 additions and 3 deletions.
  1. +12 −3 jquery.validate.js
View
15 jquery.validate.js
@@ -837,12 +837,21 @@ $.extend($.validator, {
for (var method in $.validator.methods) {
var value;
- // If .prop exists (jQuery >= 1.6), use it to get true/false for required
- if (method === 'required' && typeof $.fn.prop === 'function') {
- value = $element.prop(method);
+
+ if (method === 'required') {
+ value = $element.get(0).getAttribute(method);
+ // Some browsers return an empty string for the reqired attribute
+ // and non-HTML5 browsers might have required="" markup
+ if (value === "") {
+ value = true;
+ } else if (value === "false") {
+ value = false;
+ }
+ value = !!value; //force non-HTML5 browsers to return bool
} else {
value = $element.attr(method);
}
+
if (value) {
rules[method] = value;
} else if ($element[0].getAttribute("type") === method) {
Something went wrong with that request. Please try again.