"Reprint" jquery Validate validation plugin, validation in AJAX submission mode

Source: Internet
Author: User

Normal forms are submitted using the Submit button, and the jquery Validate plugin makes it easy to do forms validation.

To do a text messaging function, to the target table to insert multiple records, the interface using AJAX to submit the form, waiting for the effect directly with the Ext mask.

But how to verify and run into problems.

The solution is simple, the form is the same as the normal form, the validate of the Submithandler,invalidhandler 2 methods need to overwrite, all return false, so that the form will not be submitted when the button click, form validation and normal validation work. Submithandler write our form processing code before the return is OK.

The code below, you can ignore ext related code.

1 //Form Validation2$ ("#query"). Validate ({3OnKeyUp:false,4OnClick:false,5Onfocusout:false,6 rules: {7 msg: {8Required:true,9Maxlength:10Ten                 }  One             }, A messages:{ - msg:{ -Required: ' Please input SMS content! ', theMaxLength: ' Longer than 10! ' -                 }  -             }, -ShowErrors:function(Errormap, errorlist) { +                 varmsg = "";  -$.each (Errorlist,function(i,v) { +msg + = (v.message+ "\ r \ n");  A                 });  at                 if(msg!= "") -Ext.Msg.alert (' form ', MSG +fix); -             }, -Invalidhandler:function(){ -                 return false; -             }, inSubmithandler:function(){ -                 //Processing of Forms toExt.Msg.confirm ("Confirm", "confirm send?" + fix,function(button,text) { +                    if(Button = = ' Yes '){ - loadmarsk.show (); the $.ajax ({ *URL: ' <%=basepath%>promotionaction.do?method=group ', $DataType: ' JSON ',Panax NotoginsengType: ' Post ', -data:$ (' #query '). Serialize (), theErrorfunction(){ +Ext.Msg.alert (' Error ', ' request error! ' +fix); A loadmarsk.hide (); the                                }, +Successfunction(data) { -Ext.Msg.alert (' success ', Data.msg +fix); $ loadmarsk.hide (); $                                } -                            }) -                    } the} );//Confirm -                 return false;//block form submissionWuyi             } the});

The key is: Validate's Submithandler,invalidhandler These 2 methods all need to overwrite, all return false;

Transferred from: http://www.cnblogs.com/longterm/archive/2012/05/18/2507594.html

"Reprint" jquery Validate validation plugin, validation in AJAX submission mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.