2
I am using the jQuery Validate library to do some validations on a form and would like to know if anyone knows how to make the focus stay in the field always, in case it is invalid. Currently, it exits the invalid field but does not submit until corrected. Follows code:
$(document).ready( function() {
$("#cadastro").validate({
// Define as regras, pega sempre pela ID. Se não passar (caso do combo) usa o Name.
rules:{
cracha:{
// ordem será obrigatório (required), numérico e terá tamanho mínimo (minLength)
required: true, number: true, minlength: 4
}
},
// Define as mensagens de erro para cada regra
messages:{
cracha:{
required: "Passe o crachá! ",
number: "Somente numeros!",
minlength: "Minimo 4 digitos!"
}
}
});
});
Any idea?
It should already work by default. Try to put the option
focusInvalid: true
– Franchesco
It worked out.... Thank you!
– Diego