Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 349
ccppjava Avatar asked Oct 25 '22 15:10

ccppjava


1 Answers

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

$("#myform").validate({
   ignore: ".ignore"
})
like image 74
Gabe Avatar answered Nov 15 '22 13:11

Gabe