Force at least one field to be mandatory

2

I have 4 CheckBox in my form HTML , I'm working on the validations only with Jquery.Validate , is there a way I can set at least 1 of these checBox's on?

Any property of validate ? Or just creating a role in the race?

I found something about here Apparently the solution seems practical and viable, so in my case I do not have a name for the checkedbox group

My code looks like this:

<td colspan="2">Você conversou com quem?
   <input type="checkbox" name="Diretor" id="Diretor" />Diretor
   <input type="checkbox" name="Vice" id="Vice" />Vice-Diretor
   <input type="checkbox" name="Coordenador" id="Coordenador" />Coordenador
   <input type="checkbox" name="Nenhum" id="Nenhum"  />Não conversei com ninguem
</td>
    
asked by anonymous 03.09.2014 / 20:03

1 answer

1

I think what you need is the require_from_group method that validates if an element in a group is populated.

On the plugin page you have this example:

$( "#myform" ).validate({
  rules: {
    mobile_phone: {
      require_from_group: [1, ".phone-group"]
    },
    home_phone: {
      require_from_group: [1, ".phone-group"]
    },
    work_phone: {
      require_from_group: [1, ".phone-group"]
    }
  }
});

In your case the code could look like this: link

Then you need to have these files loaded:

<script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script><scriptsrc="http://jqueryvalidation.org/files/dist/additional-methods.min.js"></script>
    
03.09.2014 / 20:09