Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Validation: Call Valid without displaying errors?

Tags:

Using JQuery Validation plugin, I am trying to call the .valid() method without the side-effects of displaying error messages on screen. I have tried a number of scenarios with no success, my latest being:

$('#signup').validate({
            showErrors: function() { return; },
            errorElement: "",
            errorClass: "",
            errorPlacement: function() { },
            invalidHandler: function() { },
            highlight: function(element, errorClass) { },
            unhighlight: function(element, errorClass) { }
        });

$('#displayPurposes').text("Valid: " + $("#EMailAddress_EmailAddress").valid());

Whilst the .valid() call is working correctly it is still causing side-effects of displaying error messages.

I don't want this to happen, help please.

like image 428
soul Avatar asked Oct 13 '10 10:10

soul


1 Answers

You can do this without using CSS hacks by calling checkForm().

var isValid = $('#signup').validate().checkForm(); // true|false

checkForm() does not trigger UI changes.

However, there is one side effect. Form fields will now be validated on change/focus/blur, which may be undesirable. You can disable this behavior by resetting the submitted object:

$('#signup').validate().submitted = {};

Which results in:

var validate = $('#signup').validate(); // Get validate instance
var isValid = validate.checkForm(); // Valid?
validate.submitted = {}; // Reset immediate form field checking mode
like image 197
Blaise Avatar answered Sep 28 '22 11:09

Blaise