Skip to content Skip to sidebar Skip to footer

Jquery Validate Require From Group Not Working

Having some trouble with this function of the validation plugin: http://jqueryvalidation.org/require_from_group-method Related part of the form: core library, validation won't work.

Make sure you're also referencing additional-methods.min.js

Fiddle Example

Once you have all of the required references, you'll need to modify your html content, so that all of your check boxes have the same name. Validation won't work if all of the names are unique. The ids will obviously have to remain unique.

Updated Html:

<form id="orgform">
  <input class="org-group"type="checkbox" name="org"id="org[1]" value="on">
  <input class="org-group"type="checkbox" name="org"id="org[2]" value="on">
  <input class="org-group"type="checkbox" name="org"id="org[3]" value="on">
  <input class="org-group"type="checkbox" name="org"id="org[4]" value="on">
  <input type="submit" value="Validate">
</form>

Notice that all of the checkboxes have a name of "org".

After you've updated your html, update the call to validate to reference "org" instead of "org[]". If you inspect the console you'll notice the following error:

UncaughtSyntaxError: Unexpected token [

This is because the rules property doesn't accept [ or ]

With the html changes, you'll also need to update your JQuery.

Updated JQuery:

$("#orgform").validate({
  rules: {
    org: {
      require_from_group: [1, ".org-group"]
    }
  }
});

Note: Please see the Fiddle example I've linked above for a working example.

Post a Comment for "Jquery Validate Require From Group Not Working"