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

前端 未结 2 1280
陌清茗
陌清茗 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 04:55

    Why not just have a cancel function?

    Change your button to be something like

     <input type="button" class="btncat_deselected cancel"  id="Pet3btncat" value="Cancel" />
    

    And then add a listener to it with jQuery

    $(function() {
         $("#Pet3btncat").live('click',function() {
                $('#myform.input').html('');
         });
    });
    
    0 讨论(0)
  • 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('<img src="../images/next.gif" alt="submit this form" style="cursor:pointer;" />')
            $('#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.

    0 讨论(0)
提交回复
热议问题