简体   繁体   中英

Parsley.js submit form with failed validation

I am using two groups in Parlsey.js, one for warnings and one for critical errors. The form should still submit if warnings fail, but not submit if critical errors fail.

I've tried using $('form').off('form:validate'); which i saw on another post, but it doesn't appear to do anything.

Ideally, I would like to only prevent the form submission if the critical group fails, but I doubt Parsley.js supports this. However, it seems there should be a way to tell Parsley.js to always submit the form regardless of it being valid or not. I could then register a submit handler to check only the critical group and prevent submission if it fails.

I can't find anything in the documentation to do this. Any help is greatly appreciated!

There's no documented way to do this.

You could intercept the submit event, call Parsley to do the validation of your two groups, and if you are satisfied with the result, then call $('.your-form').parsley()._submit() .

As the name starts with _ , it's meant to be a private method though. Also, _submit triggers another 'submit' event, so you need to ignore it ( like in this code ).

FWIW, Parsley aims to go beyond builtin HTML5 validations while still being compatible with them . What you want to do actually goes against the HTML5 standard, so it's quite reasonable that it's not "easy" to do.

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