How to dynamically add and cancel verification items in BootStrap

Source: Internet
Author: User

How to dynamically add and cancel verification items in BootStrap

BootstrapValidator in bootstrap can verify the front-end data, but sometimes we need to dynamically add verification, so we need to dynamically modify the content of bootstrapValidator.

  The traditional bootstrapValidator verification is

$ ('# MaintainEntryForm'). bootstrapValidator ({message: 'The input value is invalid! ', FeedbackIcons: {valid: 'glyphicon glyphicon-OK', invalid: 'glyphicon glyphicon-removing ', validating: 'glyphicon glyphicon-refresh'}, fields: {Specifications: {validators: {notEmpty: {message: 'enter the specification! '}}, ProductNameEN: {validators: {notEmpty: {message:' enter an English name! '}}, ApplyUnit: {validators: {notEmpty: {message:' enter the reporting unit! '}, StringLength: {min: 1, max: 3, message:' the reporting unit can enter up to 3 bits! '}}, Sutleweight: {validators: {notEmpty: {message:' enter the net weight! '}, // Regexp: {regexp:/^ \ d {0, 8} \. {0, 1} (\ d {1, 3 })? $/, Message: 'net weight can only be an integer greater than or equal to 0 or three decimal places! '}, Callback: {message:' The net weight can only be an integer greater than 0 or three decimal places! ', Callback: function (value, validator, $ field) {var reg =/^ \ d {} \. {} (\ d })? $/; Return parseFloat (value)> 0 & reg. test (value );}}}}}}). on ("success. form. bv ", function (e) {if (EntryInfo. saveType = 1) {EntryInfo. saveEntryInfo ();} else if (EntryInfo. saveType = 2) {EntryInfo. saveAndSubmitAudit ();}});

Such verification does not meet the conditions when there is a page interaction requirement. Therefore, we need to dynamically modify the verification conditions, here, we add all the conditions that may be used first, and remove the filtering conditions after the specified conditions.

  Removal Method

$('#MaintainEntryForm').data('bootstrapValidator').validateField('ApplyUnit');

In this way, verification with the name ApplyUnit will not work anymore.

You can use the following methods to remove verification information if an error message has been reported:

$('#MaintainEntryForm').data('bootstrapValidator').updateStatus('ApplyQty', 'NOT_VALIDATED', null).validateField('ApplyQty');

In this way, the verification information after the ApplyQty field corresponding to the page will disappear without resetting the entire bootstrapValidator.

The above section describes how to dynamically add and cancel verification items in BootStrap. I hope it will be helpful to you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. 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.