I'm using the Bootstrap Validator , the form validation is working very well. However, I wanted the validation of the nome
field to be executed only when the user finished typing.
The validation of this field makes a request ajax
synchronously, and this causes some brakes to occur during typing.
$("#frmImovel").validator({
disable: false,
custom: {
existingName: function($el) {
var teste = "";
$.ajax({
url: 'https://www.hobbietech.com.br/VitrineImoveis/adm/data-remote-validations/nome_imovel_existente.php',
datatype: 'json',
data: {
idImovel: $el.data("existingname"),
nome: $el.val()
},
async: false,
success: function (response) {
response = JSON.parse(response);
if (response.result === false) {
teste = response.mensagem;
}
}
});
return teste;
}
}
});
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><linkhref="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://www.hobbietech.com.br/VitrineImoveis/adm/js/validator.min.js"></script><formid="frmImovel" data-toggle="validator" role="form">
<div class="form-group col-md-4">
<label for="txtNome" class="control-label">Nome</label>
<input id="txtNome" name="nome" class="form-control"
data-existingname="0"
placeholder="Nome do Imóvel" type="text"
data-required-error="Por favor, informe o nome do imóvel!"
data-remote-error="Já existe um imóvel com este nome!"
required
>
<div class="help-block with-errors"></div>
</div>
</form>