Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check that the unobtrusive validations has been validated in jquery function?

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; }
}
}   
like image 896
Kriitika Avatar asked Nov 23 '11 06:11

Kriitika


People also ask

How do you check if jQuery validate is working?

The plugin adds a validationPlugin function to jQuery. fn , so simply check whether it exists or not; if (typeof jQuery. fn.

What is jQuery validate unobtrusive?

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.

How do you check if a form is valid?

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 .

What is validator unobtrusive parse?

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.


1 Answers

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
    }
});
like image 148
Darin Dimitrov Avatar answered Sep 27 '22 21:09

Darin Dimitrov