Within a single form
I have 3 divs
, which will change as the user clicks próximo
. But for the user to be able to click on próximo
the required fields of div
that is currently being displayed must be filled in.
To validate form
has a code like this:
var form_validation = function() {
var e = function() {
jQuery(".form-valide").validate({
ignore: [],
errorClass: "invalid-feedback animated fadeInDown",
errorElement: "div",
errorPlacement: function(e, a) {
jQuery(a).parents(".form-group > div").append(e)
},
highlight: function(e) {
jQuery(e).closest(".form-group").removeClass("is-invalid").addClass("is-invalid")
},
success: function(e) {
jQuery(e).closest(".form-group").removeClass("is-invalid"), jQuery(e).remove()
},
rules: {
"nome_campo":{
required: !0
}
},
messages:{
"nome_campo":{
required: "mensagem a ser mostrada quando não preenchido"
}
}
})
}
return {
init: function() {
e(), a(), jQuery(".js-select2").on("change", function() {
jQuery(this).valid()
})
}
}
}();
jQuery(function() {
form_validation.init()
});
In this way I can specify the field that is required and the error message to be displayed. But as far as I researched I can only do this for tag form
, but not for div
.
I was wondering if there is any way to do something similar for divs
and only allow it to move to the next div
when all required fields are filled and so on until you get to div
which allows you to click% with%. But if the user clicks salvar
and the required fields are not filled up it shows the error messages.