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!