Use class instead of id in Jquery Validate

0

I have this Jquery Validate script:

/****** Validate ******/
$().ready(function() {


  $("#form_inserir_imagem").validate({
    rules: {
      id_cat: "required",
      image_file: "required",
      nome_servico: "required",
    },

    messages: {
      id_cat: "Selecione alguma categoria",
      image_file: "Selecione uma imagem ou verifique se o arquivo é Jpg",
      nome_servico: "Informe o nome do serviço"
    }
  });


});
<script src="https://www.agenciamove.com.br/painel_ctr/assets/global/plugins/jquery.min.js"type="text/javascript"></script>

<script type="text/javascript" src="https://www.agenciamove.com.br/painel_ctr/assets/global/plugins/jquery-validation/js/jquery.validate.min.js"></script><scripttype="text/javascript">
</script>







<form action="" name="form_inserir_imagem" id="form_inserir_imagem" class="horizontal-form" method="post" enctype="multipart/form-data">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
    <h4 class="modal-title">Inserir imagem</h4>
  </div>
  <div class="modal-body">
    <div class="row">
      <div class="col-md-6">
        <div class="form-group">
          <label class="control-label">Categoria</label>
          <select name="id_cat" id="id_cat" class="bs-select form-control id_cat_teste" tabindex="13">
            <option selected disabled="disabled"> Selecione</option>

            <option> Teste</option>

          </select>
        </div>
      </div>
    </div>

    

  <div class="modal-footer">
    <button type="button" class="btn dark btn-outline" data-dismiss="modal" tabindex="20">Fechar</button>
    <button type="submit" class="btn green" tabindex="19">Salvar</button>
    <input type="hidden" name="inserir_imagem" value="ok" />
    <input type="hidden" name="id_cliente_imagem_up" value="<?php echo $idItem; ?>">

    <!-- Hidden crop params -->
    <input type="hidden" id="x1" name="x1" />
    <input type="hidden" id="y1" name="y1" />
    <input type="hidden" id="x2" name="x2" />
    <input type="hidden" id="y2" name="y2" />
  </div>
</form>

In the page itself, it is necessary for the validate to work instead of the id "cat_id", with the "cat_test_id" class.

The documentation has the

jQuery.validator.addClassRules("name", {
  required: true,
  minlength: 2
});

But it does not work.

    
asked by anonymous 02.05.2018 / 00:56

0 answers