Skip to content
This repository

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

Closed
wants to merge 1 commit into from

2 participants

Max Lynch Jörn Zaefferer

Showing 1 unique commit by 1 author.

Apr 04, 2012
Max Lynch mlynch required attribute fix for non-html5 browsers. Fixes #301 d18d510
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 12 additions and 3 deletions. Show diff stats Hide diff stats

  1. +12 3 jquery.validate.js
15 jquery.validate.js
@@ -837,12 +837,21 @@ $.extend($.validator, {
837 837
838 838 for (var method in $.validator.methods) {
839 839 var value;
840   - // If .prop exists (jQuery >= 1.6), use it to get true/false for required
841   - if (method === 'required' && typeof $.fn.prop === 'function') {
842   - value = $element.prop(method);
  840 +
  841 + if (method === 'required') {
  842 + value = $element.get(0).getAttribute(method);
  843 + // Some browsers return an empty string for the reqired attribute
  844 + // and non-HTML5 browsers might have required="" markup
  845 + if (value === "") {
  846 + value = true;
  847 + } else if (value === "false") {
  848 + value = false;
  849 + }
  850 + value = !!value; //force non-HTML5 browsers to return bool
843 851 } else {
844 852 value = $element.attr(method);
845 853 }
  854 +
846 855 if (value) {
847 856 rules[method] = value;
848 857 } else if ($element[0].getAttribute("type") === method) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.