jQuery Validation插件:当存在SubmitHandler处理程序时,禁用对指定提交按钮的验证 [英] jQuery Validation plugin: disable validation for specified submit buttons when there is submitHandler handler

查看:132
本文介绍了jQuery Validation插件:当存在SubmitHandler处理程序时,禁用对指定提交按钮的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,我正在使用umbraco论坛模块,并且在注释表单上使用了jquery validate插件. 问题是我使用UserControl在同一页面上添加了搜索按钮,搜索提交按钮触发了评论表单提交验证.

Ok, I am using umbraco forum module, and on the comment form it uses jquery validate plugin. The problem is that I have added a search button on the same page using a UserControl, the search submit button triggers the comment form submission validation.

我做了一些研究,并在按钮中添加了取消" css类.这绕过了第一个验证问题,但是,它仍然属于"submitHandler".阅读了源代码,并找到了一种方法来检测搜索按钮是否触发了提交.但是,没有一种绕过处理程序的好方法.

I have done some research, and added the 'cancel' css class to the button. This bypass the first validation issue, however, it still fall into the 'submitHandler'. Have read the source code and find a way to detect whether the search button triggers the submission. however, there is not a nice way to bypass the handler.

我当前使用的是丑陋的方法:创建JavaScript错误!我想知道一种更好的方法来完成这项工作.非常感谢!

I am currently using a ugly way to do it: create javascript errors! I would like to know a nicer way to do the job. Many thanks!

顺便说一句,我目前正在使用:

Btw, I am currently using:

submitHandler: function (form) {

            $(form).find(':hidden').each(function () {
                var name = $(this).attr('name');
                if (name && name.indexOf('btnSearch') === name.length - 'btnSearch'.length) {
                    // this is a dirty hack to avoid the validate plugin to work for the button
                    eval("var error = 1 2 ''");
                }
            });

            // original code from umbraco ignored here....
        }

......

这里有类似的问题: jQuery验证插件:对指定的提交按钮禁用验证 (这有点不同,因为在此示例中使用了SubmitHandler ...)

there is similar question here: jQuery Validation plugin: disable validation for specified submit buttons (it is a little bit different, as the submitHandler is used in this one...)

推荐答案

使用ignore并将选择器设置为所需的任何内容.

Use ignore and set the selector to whatever you need it to be.

$("#myform").validate({
   ignore: ".ignore"
})

这篇关于jQuery Validation插件:当存在SubmitHandler处理程序时,禁用对指定提交按钮的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆