jquery validation on error code example
Example: jquery validation errorplacement
$(document).ready(function () {
$('#add_client').validate({
errorClass: 'validation_errors',
debug: false,
rules: {
client_name: {
required: true
},
client_address: {
required: true
},
client_city: {
required: true
}
},
errorPlacement: function (error, element) {
console.log('dd', element.attr("name"))
if (element.attr("name") == "client_city") {
error.appendTo("#messageBox");
} else {
error.insertAfter(element)
}
},
messages: {
client_name: {
required: "The Client name is a required / mandatory field"
},
client_address: {
required: "The Client address is a required / mandatory field"
},
client_city: {
required: "The City is a required / mandatory field"
},
},
submitHandler: () => {
$('#send_form').on('click', submitFormHandler)
$('#send_form').trigger('click')
$('#terms-of-use').removeClass("checked")
$('#terms').removeClass("checked")
}
});
});