0

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?

2
  • Hiya, Should I flick you a working demo of Validation frame work because it seems you are missing the point how validation work :) please let me know if that helps, cheers Commented Jun 8, 2012 at 20:48
  • @Tats_innit Yea absolutely feel free to point me in the right direction. I've read through the documentation and checked out the demos from the link I provided, but there's nothing that fits my situation as far as I can tell. Commented Jun 8, 2012 at 20:57

1 Answer 1

1

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
     }
    });
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but this just calls omniSearchVaidate on submit, basically like rolling my own validation in the form.submit event. It doesn't hook my omniSearchVaidate into jQuery Validation. In short, it doesn't allow me to automatically show a validation message associated with omniSearchVaidate. Also, this won't work with partial-postbacks.
add **$(this).validationEngine('showPrompt', '* Please fill at least one', 'red', 'topRight',true)** on else condition of if ($.trim($(this)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.