问题描述:

I'm having a performance problem due to a big form I have where there is a table that can contain 100+ records. The reason is that when I submit the form the validation for every single item is fired and this is causing a 5s delay which is unacceptable.

Is there a way to disable this just for this event in this form? I'm performing the validations on the onblur event and on the serverside, so I think it will be safe if I just skip it on the onsubmit event.

I've tried the following and it has not worked:

//1

$.validator.setDefaults({

onsubmit: false

});

//2

var validationSettings = $.data($('form')[0], 'validator').settings;

validationSettings.onsubmit = false;

//3

$("form").validate().cancelSubmit = true; //This is on the onclick of the submit button

网友答案:

If you add the class cancel to your submit button, that will signal jquery.validate.js that validation should not be done when the submit button is clicked.

UPDATE

jquery.validate.js contains the following:

// allow suppresing validation by adding a cancel class to the submit button
inputsAndButtons.filter(".cancel").click(function () {
    validator.cancelSubmit = true;
});

Based on the behavior you are reporting, you must have something else attached to your submit event which is overriding the behavior of jquery.validate for a submit button with the cancel class.

Please examine each step in the image you posted of the event progress. There is almost certainly something in that tree which will indicate where the default behavior is being overridden.

相关阅读:
Top