[Reprinted] jquery validate verification plug-in, verification in ajax submission mode, jqueryvalidate
Normal Forms are submitted using the submit button. The jquery validate plug-in can easily perform form verification.
The function of sending text messages inserts multiple records into the target table. The interface uses ajax to submit the form, and the ext mask is used for the effect.
But how to verify it has encountered problems.
The solution is very simple. The form is the same as the normal form. The submitHandler and invalidHandler methods of validate must be overwritten and both return false. In this way, the form will not be submitted when the button is clicked, form Verification works with normal verification. SubmitHandler can write our form processing code before return.
The Code is as follows. You can ignore ext-related code.
1 // Form Verification 2 $ ("# query "). validate ({3 onkeyup: false, 4 onclick: false, 5 onfocusout: false, 6 rules: {7 msg: {8 required: true, 9 maxlength: 1010} 11 }, 12 messages: {13 msg: {14 required: 'enter the text message content! ', 15 maxlength:' The length exceeds 10! '16} 17}, 18 showErrors: function (errorMap, errorList) {19 var msg = ""; 20 $. each (errorList, function (I, v) {21 msg + = (v. message + "\ r \ n"); 22}); 23 if (msg! = "") 24 Ext. msg. alert ('form', msg + fix); 25}, 26 invalidHandler: function () {27 return false; 28}, 29 submitHandler: function () {30 // form processing 31 Ext. msg. confirm ("OK", "Are you sure you want to send? "+ Fix, function (button, text) {32 if (button = 'yes') {33 loadMarsk. show (); 34 $. ajax ({35 url: '<% = basePath %> promotionAction. do? Method = group ', 36 dataType: 'json', 37 type: 'post', 38 data: $ (' # query '). serialize (), 39 error: function () {40 Ext. msg. alert ('error', 'request error! '+ Fix); 41 loadMarsk. hide (); 42}, 43 success: function (data) {44 Ext. msg. alert ('success', data. msg + fix); 45 loadMarsk. hide (); 46} 47}) 48} 49}); // confirm50 return false; // prevent form submission 51} 52 });
The key lies in: validate's submitHandler and invalidHandler must be overwritten and both return false;