Foreground validation Framework Jquery-validation-engine

Source: Internet
Author: User

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; }




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.