How do I remove jQuery validation from a form?

后端 未结 10 1528
逝去的感伤
逝去的感伤 2020-12-02 20:10

I\'m using the jQuery validation plugin to validate a form, and I\'d like to remove the validation and submit the form if a certain link is clicked.

I am submitting

相关标签:
10条回答
  • 2020-12-02 20:29

    I recently upgraded to 1.5.5 of Jörn's validator script and the removeValidator function has been deprecated.

    
    ...
    jQuery.extend(
              jQuery.fn, 
              {
              removeValidator: function(){
                  this.unbind();
                  jQuery.removeData(this[0], 'validator'); 
              }
    ...
    
    0 讨论(0)
  • 2020-12-02 20:30

    I have found none of the other ways helpful if you wanted to toggle on/off your forms validation (e.g. different validation for payment types...)

    What I have had to do (this is not an nice fix but it does work)

    Set up your validation:

    jQuery('#form').validate();
    

    Disabling the form:

    jQuery('#form').validate().currentForm = '';
    

    Enabling the form again:

    jQuery('#form').validate().currentForm = jQuery('#form')[0];
    
    0 讨论(0)
  • 2020-12-02 20:32

    You can remove events of nodes with unbind:

    jQuery('form#listing').unbind('submit'); // remove all submit handlers of the form
    

    What you are probably looking for is that the validation plugin can also unassign itself from the submit event:

    jQuery('form#listing').validate({
       onsubmit : false
    });
    

    For both of these you should be able to follow up with a call to .submit() to submit the form:

    jQuery('form#listing').unbind('submit').submit();
    
    0 讨论(0)
  • 2020-12-02 20:32

    This seems to work for me now:

    var form = $('#my_form_id').get(0);
    $(form).removeData('validate');
    
    0 讨论(0)
  • 2020-12-02 20:35

    You can add a css class of cancel to an element (button, input) so that it skips the validation

    0 讨论(0)
  • 2020-12-02 20:38
    var form = $('#my_form_id').get(0);
    $.removeData(form,'validator');
    

    Is really working.

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