Browse Source

#406: Add revalidateField() method

phuoc 11 years ago
parent
commit
175a188668
5 changed files with 39 additions and 7 deletions
  1. 1 0
      CHANGELOG.md
  2. 3 4
      demo/date.html
  3. 16 0
      dist/js/bootstrapValidator.js
  4. 3 3
      dist/js/bootstrapValidator.min.js
  5. 16 0
      src/js/bootstrapValidator.js

+ 1 - 0
CHANGELOG.md

@@ -23,6 +23,7 @@ __New Features__
 * [#336](https://github.com/nghuuphuoc/bootstrapvalidator/issues/336): Add ```$field``` instance to the [callback validator](http://bootstrapvalidator.com/validators/callback/)
 * [#356](https://github.com/nghuuphuoc/bootstrapvalidator/issues/356): Add ```group``` option
 * [#374](https://github.com/nghuuphuoc/bootstrapvalidator/pull/374): Add Singapore postal code to the [zipCode validator](http://bootstrapvalidator.com/validators/zipCode/), thanks to [@thisisclement](https://github.com/thisisclement)
+* [#406](https://github.com/nghuuphuoc/bootstrapvalidator/issues/406): Add ```revalidateField(field)``` method
 
 __Changes__
 * [#42](https://github.com/nghuuphuoc/bootstrapvalidator/issues/42): Remove the submit button from ```submitHandler()```. You can use new ```getSubmitButton()``` method to get the clicked submit button

+ 3 - 4
demo/date.html

@@ -160,10 +160,9 @@ $(document).ready(function() {
     $('#datetimePicker')
         .on('dp.change dp.show', function(e) {
             // Validate the date when user change it
-            $('#defaultForm')
-                .data('bootstrapValidator')                                 // Get the bootstrapValidator instance
-                .updateStatus('datetimePicker', 'NOT_VALIDATED', null)      // Mark the field as not validated, so it'll be re-validated when the user change date
-                .validateField('datetimePicker');                           // Validate the field
+            $('#defaultForm').data('bootstrapValidator').revalidateField('datetimePicker');
+            // You also can call it as following:
+            // $('#defaultForm').bootstrapValidator('revalidateField', 'datetimePicker');
         });
 });
 </script>

+ 16 - 0
dist/js/bootstrapValidator.js

@@ -1190,6 +1190,20 @@
         },
 
         /**
+         * Revalidate given field
+         * It's used when you need to revalidate the field which its value is updated by other plugin
+         *
+         * @param {String|jQuery} field The field name of field element
+         * @returns {BootstrapValidator}
+         */
+        revalidateField: function(field) {
+            this.updateStatus(field, this.STATUS_NOT_VALIDATED)
+                .validateField(field);
+
+            return this;
+        },
+
+        /**
          * Enable/Disable all validators to given field
          *
          * @param {String} field The field name
@@ -1383,6 +1397,8 @@
 
     // Available validators
     $.fn.bootstrapValidator.validators = {};
+
+    // i18n
     $.fn.bootstrapValidator.i18n       = {};
 
     $.fn.bootstrapValidator.Constructor = BootstrapValidator;

File diff suppressed because it is too large
+ 3 - 3
dist/js/bootstrapValidator.min.js


+ 16 - 0
src/js/bootstrapValidator.js

@@ -1189,6 +1189,20 @@
         },
 
         /**
+         * Revalidate given field
+         * It's used when you need to revalidate the field which its value is updated by other plugin
+         *
+         * @param {String|jQuery} field The field name of field element
+         * @returns {BootstrapValidator}
+         */
+        revalidateField: function(field) {
+            this.updateStatus(field, this.STATUS_NOT_VALIDATED)
+                .validateField(field);
+
+            return this;
+        },
+
+        /**
          * Enable/Disable all validators to given field
          *
          * @param {String} field The field name
@@ -1382,6 +1396,8 @@
 
     // Available validators
     $.fn.bootstrapValidator.validators = {};
+
+    // i18n
     $.fn.bootstrapValidator.i18n       = {};
 
     $.fn.bootstrapValidator.Constructor = BootstrapValidator;