How to manually trigger validation with jQuery validate?
Or one can simply use: $('#myElem').valid()
if ($('#myElem').valid()){
// will also trigger unobtrusive validation only for this element if in place
// add your extra logic here to execute only when element is valid
}
Note that validate()
needs to be called on the form before checking it using this method.
Documentation link: https://jqueryvalidation.org/valid/
My approach was as below. Now I just wanted my form to be validated when one specific checkbox was clicked/changed:
$('#myForm input:checkbox[name=yourChkBxName]').click(
function(e){
$("#myForm").valid();
}
)
That library seems to allow validation for single elements. Just associate a click event to your button and try the following:
$("#myform").validate().element("#i1");
Examples here:
https://jqueryvalidation.org/Validator.element