GitHub Address: Https://github.com/posabsolute/jQuery-Validation-Engine
A Chinese document address: http://code.ciaoca.com/jquery/validation_engine/
Normal validation is not said, reference documentation and very clear.
Write an AJAX validation of field here.
The demo implementation feature is a simple, unique validation that returns information after validation through the Jquery-validation-engine Ajax submission background.
First, give input class
<path= "title" class= "Form-control validate[required,ajax[ Ajaxunique]] " ID=" Foddertitle " placeholder=" text message title "/>
Ajax[ajaxunique] is the validation of Ajax Ajaxunique is a validation rule that needs to be configured, as follows
Add an AJAX validation rule to the $.validationenginelanguage.allrules that corresponds to the introduced language pack, which has given an example of annotations,
I'm adding it here.
"Ajaxunique": { "url": "/portal/fodder/newvalidatetitle.do", "extradata": "", "extradatadynamic": [' #fodderTitle ', ' #fodderId '], "Alerttext": "* Sorry, the title you entered already exists", "Alerttextok": "* Title available", "alerttextload": "* Verifying ..." }
parameter Description:
Extradata is an ajax request parameter such as "Extradata": "Name=eric", the parameter name submitted to the background is name, and the value is Eric
The extradatadynamic is also the ID in the request parameter configuration input, which automatically obtains the value of input based on the ID, and the parameter name submitted to the background is the ID of the configuration here.
Alerttext " "Alerttextok" "alerttextload corresponding error message, validation pass, and information being validated , how to determine whether the correct is based on the return information in the background,
Send Ajax request default get mode: Client calls url?fieldid=id1&fieldvalue= value1 ==> Server
( FieldID and Fieldvalue are automatically uploaded to the background by default, based on the AJAX validation rules you configured on that input I have a duplicate configuration here in Extradatadynamic, actually foddertitle is can be directly from fieldvalue get )
The format returned by the background should be an array: Client receives << Span class= "title" >== ["id1", boolean, ERRORMSG] server
The first value type is String, the value that is received by the FieldID, and the second value type is Boolean, which is verified by returning true, not by returning false, the third error message I don't use it here.
Here's a look at the backend code:
@RequestMapping ("/newvalidatetitle.do") Public@ResponseBody List<Object>validatetitle (String foddertitle,string fodderid,string fieldid) {List<Object> res=NewArraylist<> (2); Res.add (FieldID); if(Commonutils.isempty (foddertitle)) {Res.add (false); returnRes; } List<WxFodderDto> list=Fodderservice.findbytitle (Foddertitle); if(Commonutils.isnotempty (Fodderid)) {if(List.isEmpty () | | (List.size () ==1&&list.get (0). GetId (). Equals (Fodderid)) {Res.add (true); returnRes; } }Else{ if(List.isEmpty ()) {Res.add (true); returnRes; }} res.add (false); returnRes; }