jQuery Validation plugin: disable validation for specified submit buttons when there is submitHandler handler

一曲冷凌霜 提交于 2019-12-07 05:46:38

问题


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.

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.

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....
        }

...............

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...)


回答1:


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

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


来源:https://stackoverflow.com/questions/2820647/jquery-validation-plugin-disable-validation-for-specified-submit-buttons-when-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!