jQuery验证器绕过表单中的某个字段的验证。

时间:2022-08-24 22:21:10

I can't figure out how to bypass a form field inside a form when a certain button is clicked.

当单击某个按钮时,我不知道如何绕过表单中的表单字段。

Example:

例子:

In my case, I want to bypass the newpassword and newpassword2 (which is needed if the user wants to change password) because I have a button so the user can delete his account. Without bypass, he has to fill in a newpassword and confirm it before he can delete his account.

在我的例子中,我想绕过newpassword和newpassword2(如果用户想要更改密码,这是必需的),因为我有一个按钮,所以用户可以删除他的帐户。没有旁路,他必须填写一个新密码并在他删除他的帐户之前确认它。

These are the id's:

这些id:

  • Delete button: deletemyacc
  • 删除按钮:deletemyacc
  • Form name: updelacc (because update / delete account option within this form)
  • 表单名称:updelacc(因为在此表单中更新/删除帐户选项)
  • Form field names to bypasss: newpassword and newpassword2
  • 表单字段名到bypasss: newpassword和newpassword2。

Now this code works, but it skips ALL validations, while I still want the old password form field to be validated and the users email.

现在这个代码起作用了,但是它跳过所有的验证,而我仍然希望验证旧的密码表单字段和用户的电子邮件。

$("#deletemyacc").click(function () {
  $("#updelacc").validate().cancelSubmit = true;
});

1 个解决方案

#1


2  

Try:

试一试:

$("#deletemyacc").click(function () {
  $("#updelacc").validate({ignore: ".ignore"}).cancelSubmit = true;
});

this way ignores all elements with class 'ignore'

这种方法忽略了类“忽略”的所有元素

Source: http://docs.jquery.com/Plugins/Validation/validate#options

来源:http://docs.jquery.com/Plugins/Validation/validate选项

#1


2  

Try:

试一试:

$("#deletemyacc").click(function () {
  $("#updelacc").validate({ignore: ".ignore"}).cancelSubmit = true;
});

this way ignores all elements with class 'ignore'

这种方法忽略了类“忽略”的所有元素

Source: http://docs.jquery.com/Plugins/Validation/validate#options

来源:http://docs.jquery.com/Plugins/Validation/validate选项