JQuery Validate - class=“cancel” submit button only stops validation once

前端 未结 2 1281
陌清茗
陌清茗 2021-01-27 04:25

I have a form with buttons I do not what to Submit the form, but they are (necessarily) submit buttons. I\'ve given them the class \"cancel\" and on the first click they are can

2条回答
  •  无人及你
    2021-01-27 05:09

    Ok, using what DA commented; I ended up telling the form to NOT validate on submit ( onSubmit: false, ) and then created a function to hide the actual submit button, and have an image (or could of been a normal button) to submit the form on validation being true:

    $(function() {
    
            $('#Petform #btnNext').hide();
            $('#Petform #NextWrapper').append('submit this form')
            $('#Petform #NextWrapper img').live('click', function() { 
                      if( $('form').valid() ) {
                            $('#btnNext').click();
                      } 
                });
    
          });
    

    This way the form wont be sent to server if it isnt valid, and normal form buttons/functionality reverts if JS is disabled.

    Thanks for the replies, Guys.

提交回复
热议问题