Bootstrapvalidator Multi-field joint validation (such as Start date and end date, start date not later than end date)

Source: Internet
Author: User

Contact Bootstrapvalidator time, recently need a number of field co-verification, the web looked up a bit not found, consult the API documentation, found that can be achieved.

Look at Dom first.

<DivClass= "Form-group"><LabelClass= "Col-sm-3 Control-label"> End of Life:</Label><DivClass= "Col-sm-9 Row"><DivClass= "Col-xs-5"><DivClass= "Input-group"><InputType= "Text"Name= "Beginyear"Class= "Form-control"/><SpanClass= "Input-group-addon"> Year</Span></Div></Div><DivClass= "Col-xs-1"Style= "LINE-HEIGHT:36PX;"> To</Div><DivClass= "Col-xs-5"><DivClass= "Input-group"><InputType= "Text"Name= "Endyear"  Class= " Form-control "/> < span class= " Input-group-addon "> year </ span> </div> </div< Span style= "color: #0000ff;" >> </div>< Span style= "color: #0000ff;" ></div           

In this form, we often need to start the year not later than the end of the year, and Beginyear<=endyear, at this point, verify that we can write this

Fields: {Beginyear: {validators: {integer: {}, Callback: { Message: ' Start date cannot be greater than end Date ', Callback:function(Value, validator, $field, Options) {var begin = $ (' #pro_info '). Find ("Input[name= ' endyear ']" return parseint (value) <=parseint (begin);} }}, Endyear: {validators: {integer: {}, Callback: {message: ' End date cannot be less than start date ' ). KeyPress (); Validator.updatestatus (' beginyear ', ' VALID ' ); return parseint (value) >=parseint (begin);} }}           

The key is to use the callback function, passing in the parameter Validator Validator, using the validator to update the state of the specified field. This enables multi-field federation validation, of course, with three fields and four fields.

Reprint please indicate the source, blog Park: http://www.cnblogs.com/dreamowneryong/p/5000206.html; If in doubt, welcome to the original commentary and discuss together.

Bootstrapvalidator Multi-field joint validation (such as Start date and end date, start date not later than end date)

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.