I have a form with four fields. I have applied some unobtrusive validations to 3 of them.
I want that when all unobtrusive validation have been performed then a jquery function is called, but there I have defined an onsubmit
event on the form so that every time it first goes to that jquery function and perform all the steps then shows that the unobtrusive validation messages for the respective text boxes.
But I want to perform all steps of the jquery function if the form has passed the unobtrusive validation.
Is there a way to check that all unobtrusive validation has been performed?
This is my jquery code:
function submitDetails()
{
var check = $('#flag').val();
if (check == 1)
{
return true;
}
else {
var birthDate = ($('#BirthDate').val()).split('/');
var graduationDate = ($('#GraduationDate').val()).split('/');
var stdate = birthDate[2] + birthDate[1] + birthDate[0];
var endate = graduationDate[2] + graduationDate[1] + graduationDate[0];
if (($('#LastName').val() == "") || (parseInt(endate) < parseInt(stdate)))
{
$('#Window').data('tWindow').center().open();
return false;
}
else { return true; }
}
}
The plugin adds a validationPlugin function to jQuery. fn , so simply check whether it exists or not; if (typeof jQuery. fn.
An unobtrusive validation in jQuery is a set of ASP.Net MVC HTML helper extensions.By using jQuery Validation data attributes along with HTML 5 data attributes, you can perform validation to the client-side.
Using the email type, we can check the validity of the form field with a javascript function called… checkValidity() . This function returns a true|false value. checkValidity() will look at the input type as well as if the required attribute was set and any pattern="" tag .
validator. unobtrusive. parse(selector) method to force parsing. This method parses all the HTML elements in the specified selector and looks for input elements decorated with the [data-val=true] attribute value and enables validation according to the data-val-* attribute values.
You could check if the form is valid in the submit handler:
$('#formId').submit(function() {
if (!$(this).valid()) {
// validation failed => here you can call your function or whatever
return false;
} else {
// the form is valid => you could perform some other action if you will
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With