How to disable Validations when doing a Submit in the change event of a DropDown

1

I have a modal with a dropdown, where, whenever an option is selected, a submit is made and the template is sent to the action to be edited and then returned. The problem is that Validations get in the way, is it possible to disable validations only for the change event of my dropdown? The Save button should work normally, but for the dropdown it is necessary to disable them.

$('#pessoaNatureza').on('change', function (e) {    
  $(this).closest('form').submit();
}); 
    
asked by anonymous 28.07.2018 / 01:01

1 answer

0

From the plugin documentation, you can destroy the instance of the validator with the method:

validator.destroy();

Where validator is the name of the instance of the plugin you started. Example:

var validator = $("SELETOR DO FORMULÁRIO").validate();

Then your change event would be:

$('#pessoaNatureza').on('change', function (e) {    
   validator.destroy();
   $(this).closest('form').submit();
}); 

The validator will be disabled before submitting and the form will be submitted in the change dropdown event.

Plugin documentation

Example:

var validator = $("#commentForm").validate();
$('#pessoaNatureza').on('change', function (e) {    
   validator.destroy();
   $(this).closest('form').submit();
}); 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>

<form class="cmxform" id="commentForm" method="get" action="./">
   <p>
   <select id="pessoaNatureza">
      <option value="">Selecione...</option>
      <option value="1">1</option>
      <option value="2">2</option>
   </select>
   </p>
   <p>
   <input id="cname" name="name" minlength="2" type="text" required>
   </p>
   <button>Salvar</button>
</form>
    
28.07.2018 / 03:12