Invalid field focus jQuery Validate

2

I'm using the jQuery Validate library to do some validations on a form and would like to know if anyone knows how it could make the focus always stay in the field, in case it is invalid. Currently, it exits the invalid field but does not let it submit until corrected. Here is the 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 ideas?

    
asked by anonymous 23.06.2015 / 16:30

1 answer

2

Focus on invalid fields should already be enabled by default . But you can force activation by setting in the options, like this:

focusInvalid: true

For more information, see the plugin documentation: link

    
24.06.2015 / 13:51