开发者

How to remove validations of form

开发者 https://www.devze.com 2023-02-25 06:24 出处:网络
I\'m using jQuery.val开发者_开发问答idate plugin to validate my form that appears in popup with dynamic values. Once user click submit button error of form displayed.

I'm using jQuery.val开发者_开发问答idate plugin to validate my form that appears in popup with dynamic values. Once user click submit button error of form displayed.

Once user clicks cancel how to undo the validation that appears in form.

I used resetForm but still problem comes I am using $("#form_id").validate() with in a click function.


If you want to remove validation errors then you can .remove() to remove the error messages, then remove whatever validation class from that field

$('input.required').removeClass('required'); // no class == no future validation
$('label.error').remove();

If you want to disable validation on the entire form you can also do one of the follow, though you'll still want to remove the error messages.

$("#form_id").validate().cancelSubmit = true; // add to click event

or you can add a cancel class to your submit button

<input class="cancel" type="submit" value="Submit form" />

or add the cancel class with jquery $('#form_id input[type=submit]').addClass('cancel');

Good Luck!


I tend to use the following with JQuery.Validate if you just want to reset the validation on the cancel button.

var resetFormOnClose = function ()
{
    $('.validation-summary-errors').removeClass('validation-summary-errors').addClass('validation-summary-valid');
    $('.field-validation-error')
                .removeClass('field-validation-error')
                .addClass('field-validation-valid');

    $('.input-validation-error')
                .removeClass('input-validation-error')
                .addClass('valid');
};

so when the cancel button is clicked i just call the function resetFormOnClose(); in the event handler.

what it does is finds all instances of the error class and replaces it with the valid class.

it also just hides, by adding the valid class, the <ul></ul> where the summary informations is displayed (if you have it enabled)

0

精彩评论

暂无评论...
验证码 换一张
取 消