简体   繁体   English

Parsley.js提交失败验证表单

[英]Parsley.js submit form with failed validation

I am using two groups in Parlsey.js, one for warnings and one for critical errors. 我在Parlsey.js中使用两组,一组用于警告,一组用于严重错误。 The form should still submit if warnings fail, but not submit if critical errors fail. 如果警告失败,表单仍应提交,但如果严重错误失败则不提交。

I've tried using $('form').off('form:validate'); 我尝试过使用$('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. 理想情况下,如果关键组失败,我只想阻止表单提交,但我怀疑Parsley.js支持这一点。 However, it seems there should be a way to tell Parsley.js to always submit the form regardless of it being valid or not. 但是,似乎应该有一种方法告诉Parsley.js总是提交表单,无论它是否有效。 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() . 您可以拦截submit事件,调用Parsley来验证您的两个组,如果您对结果感到满意,则调用$('.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 ). 此外, _submit触发另一个'submit'事件,因此您需要忽略它( 就像在此代码中一样 )。

FWIW, Parsley aims to go beyond builtin HTML5 validations while still being compatible with them . FWIW,Parsley旨在超越内置的HTML5验证, 同时仍然与它们兼容 What you want to do actually goes against the HTML5 standard, so it's quite reasonable that it's not "easy" to do. 您想要做的事实上违反了HTML5标准,因此这样做并不“简单”是非常合理的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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