0

I have a nested form that uses jquery validate My question is , Can we validate/not validate entire form based on certain values?. For example I have a nested form with save / submit buttons. I want to validate only on Submit. My problem is that I have the class="required" on each field as the form is very complex and I build it on the fly. Please help.

    (function($){ 

$(document).ready(function() {

    $(".form").validate({
        debug:true,
        errorClass: "errormsg",
        ignore: ':hidden',
        meta: 'validate',
        submitHandler: function(form) {
            if ($("#stype").val() == "Submit") {

            }else{
                    form.submit();
            }
        }
    });
} );
})(jQuery);

My html looks somthing like...

<tr>
  <td width="55%">Name of Service</td>
  <td>
     <input class="required" id="application_contact_attributes__name" name="application[contact_attributes][name]" size="30" type="text" value="Demo Service 10" />
  </td>
</tr>
4
  • 1
    Can you not just remove the class="required" from the fields that aren't required? Commented Aug 18, 2011 at 18:42
  • 2
    Nested forms are not valid HTML. Commented Aug 18, 2011 at 18:45
  • @hughes my requirement is I have to either validate all the fileds when I submit or not validate when I save. Commented Aug 18, 2011 at 18:50
  • @George Cummins - Not a nested form. Its a form with rails model thats nested. That is 1 parent - multiple child, grand child. I will edit the post. Commented Aug 18, 2011 at 18:51

1 Answer 1

1

From the documentation

Can you use the onfocusout and onkeyup handlers and disable checking? I imagine these are the ones doing the validation "as you go."

$(".form").validate({
    debug:true,
    errorClass: "errormsg",
    ignore: ':hidden',
    meta: 'validate',
    onfocusout: false,
    onkeyup: false,
    onclick: false,
    submitHandler: function(form) {
        if ($("#stype").val() == "Submit") {

        }else{
                form.submit();
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

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.