简体   繁体   中英

Parsley.js, multistep form, skip validation on moving to previous step

Using ASP.NET MVC I've created a multistep form, for the client side validation I've picked Parsley.js , all works fine except when moving to a previous step in the form the validation is getting triggered (which makes perfect sense since the form is being submitted).

My Parsley related code currently looks like this

  element.parsley({
        trigger:      'change',
        successClass: "success",
        errorClass: "error",
        classHandler: function (el) {
            return el.$element.closest('.c-input'); 
        },
        errorsWrapper: '<p class="o-col-12"></p>',
        errorTemplate: '<span></span>',
    });

Where the element is my form.

Is there an easy way of saying to parsley that the validation shouldn't occur when hitting a specific button (can't see anything in the documentation...) or do I need to rework how the validation currently is attached. So only triggering the validation when hitting the next/submit button.

And yes I've looked at the multistep form example they have on the parsley site but that already has all the steps loaded and just toggles those, I need to submit between steps since server side code needs to happen.

I think you're looking for the novalidate attribute :

This Boolean attribute indicates that the form is not to be validated when submitted. If this attribute is not specified (and therefore the form is validated), this default setting can be overridden by a formnovalidate attribute on a or element belonging to the form.

Parsley respects it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM