turbo2oh
turbo2oh

Reputation: 2879

jQuery Validation require_from_group for class not working

I can't get require_from_group to work correctly with this sample form applying it to the class instead of the name. Any suggestions, not sure what I'm missing?

<h1>Form Validation Example</h1>
<form id='registerForm' name='registerForm' method='post' action='' >   <p>
   Name: <input type='text' id='name' class='fillone' />
   </p>
   <p>
   Email: <input type='text' id='email' class='fillone' />
   </p>
   <p>
   <input type='submit' name='Submit' value='Submit' />
   </p>
</form>

JS:

$(document).ready(function(){
    $("#registerForm").validate();


    $.validator.addClassRules("fillone", {
        require_from_group: [1,".fillone"]
    });
});

Fiddle: http://jsfiddle.net/1he85dwr/1/

Upvotes: 0

Views: 6730

Answers (1)

Sparky
Sparky

Reputation: 98738

The problem is that you were using an old version of the jQuery Validate plugin (1.7) along with version 1.11.1 of the additional-methods.js file (and version 1.11.0 of jQuery).

  • Version 1.7 of the plugin is very old and jQuery 1.11 is fairly new. Much has been changed within jQuery itself since then.

  • Also, the two plugin file versions (Validate and Additional Methods) should match as many of the additional methods depend on bugs that were fixed in the Validate plugin.

I updated both plugin files to the latest (version 1.13.0) and your demo started working.

http://jsfiddle.net/sparky672/1he85dwr/3/

You could also use jQuery Validate 1.11.1 or 1.12 and it should work. However, there are known bugs regarding require_from_group within versions prior to 1.11.1.

Upvotes: 3

Related Questions