Solve the problem that the validation cannot be triggered normally after a date is selected when bootstrap datepicker and bootstrapValidator are used at the same time. bootstrapvalidator

Source: Internet
Author: User

Solve the problem that the validation cannot be triggered normally after a date is selected when bootstrap datepicker and bootstrapValidator are used at the same time. bootstrapvalidator

I. Preface

You have been using bootstrap-datepicker and bootstrapValidator for some time. During work, you may find a problem when both of them are used at the same time. After you select a date, this field will not be correctly verified. To display problems more intuitively.

It can be seen that after the date is selected, the verification result is not as expected because the bootstrapValidator plug-in does not repeat a field marked as verified or not verified by default. So, when verification is triggered, the verification fails. When the date is selected correctly, the verification result is not refreshed, and the data cannot be submitted normally. When the date is changed manually, check is correctly triggered. Now let's talk about the solution.

Ii. Problem Solving

Based on the analysis of application scenarios, when the plug-in is disabled by date, verification is expected to be triggered. Therefore, use the bootstrap-datepicker hide method. When the date selection box is closed, refresh the verification. Paste the code first and then explain:

/* Select plug-in loading time */$ ("# companyRegisteTime "). datepicker ({todayBtn: "linked", autoclose: true, todayHighlight: true, endDate: new Date ()}). on ('hide ', function (e) {$ (' # enterpriseInfoForm '). data ('bootstrapvalidator '). updateStatus ('companyregistetime', 'not _ validated', null ). validateField ('companyregistetime ');});

The updateStatus method updates the validation status of a specified field. The official introduction is as follows:

The validateField method is used to trigger validation of a specified field.

BoostrapValidator official documentation at: http://bv.doc.javake.cn/api/

Bootstrap-datepicker document address: http://bootstrap-datepicker.readthedocs.io/en/latest/

Iii. Complete example

1. JSP

<Form method = "post" action = "$ {ctx}/corp/iseiseinfo/saveCorpInfo.htm" enctype = "multipart/form-data" id = "enterpriseInfoForm" name = "enterpriseInfoForm"> <div class = "col-md-5 col-md-offset-1 mar-top"> <div class = "form-horizontal"> <div class = "form-group"> <label class = "col-md-3 control -label "> company registration time: </label> <div class = "col-md-9"> <input type = "text" class = "form-control" id = "companyRegisteTime" name = "companyRegisteTime" value = "$ {corpInfo. companyRegisteTime} "> </div> </form>

2. js Initialization

<Span style = "font-size: 18px;"> $ ('# enterpriseInfoForm '). bootstrapValidator ({message: 'invalid value ', feedbackIcons: faIcon, excluded:': disabled ', fields: {companyRegisteTime: {message: 'invalid enterprise registration time', validators: {notEmpty: {message: 'enterprise registration time cannot be blank '}, date: {format: 'yyyy/MM/dd', message: 'date format incorrect '}}}}); </span>

Effect display

The above is a solution to the problem that bootstrap datepicker and bootstrapValidator cannot trigger verification normally after a date is selected for use at the same time. I hope this will be helpful to you, if you have any questions, please leave a message and the editor will reply to you in time. Thank you very much for your support for the help House website!

Related Article

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.