Josh Noe
Josh Noe

Reputation: 2797

jQuery Validate - Add custom rule not associated with a css class

Using the jQuery Validation plugin, is it possible to do custom validation on multiple elements without associating the rule or adding a css class to all of them?

In my case, I need to validate that at least one input is not blank in a certain html element.

I have this method:

function omniSearchValidate() {
    var isValid = false;

    //make sure at least one textbox is filled in
    $('#OmniSearchIndex input[type = "text"]').each(function () {
        if ($.trim($(this).val()) !== '') {
            isValid = true;
        }
    });

    return isValid;
)

How do I tell jQuery Validation to use this method on validation? Does it not work this way? Do I have to associate validation to specific elements?

Upvotes: 0

Views: 412

Answers (1)

khaled_webdev
khaled_webdev

Reputation: 1430

from documentation

 $("#myform").validate({
 submitHandler: function(form) {
   form.submit();
 }
});

so

$("#myform").validate({
     submitHandler: function(form) {
       omniSearchValidate(); //declared function
       form.submit(); //can be in function success condition
     }
    });

Upvotes: 1

Related Questions