ソースを参照

#416, #448: Add updateOption() method for updating the particular validator option, thanks to @AlaskanShade

nghuuphuoc 11 年 前
コミット
c559e0c0f4

+ 1 - 0
CHANGELOG.md

@@ -45,6 +45,7 @@ __Improvements__
 * [#382](https://github.com/nghuuphuoc/bootstrapvalidator/issues/382): Add JSHint to Grunt build
 * [#388](https://github.com/nghuuphuoc/bootstrapvalidator/issues/388): Allow to override the default options. Useful for using multiple forms in the same page
 * [#393](https://github.com/nghuuphuoc/bootstrapvalidator/pull/393): The [remote validator](http://bootstrapvalidator.com/validators/remote/) adds support for dynamic ```url``` and method type (GET/POST), thanks to [@ericnakagawa](https://github.com/ericnakagawa)
+* [#416](https://github.com/nghuuphuoc/bootstrapvalidator/issues/416), [#448](https://github.com/nghuuphuoc/bootstrapvalidator/pull/448): Add ```updateOption()``` method for updating the particular validator option, thanks to [@AlaskanShade](https://github.com/AlaskanShade)
 * [#420](https://github.com/nghuuphuoc/bootstrapvalidator/issues/420): Enable/disable particular validator
 * [#422](https://github.com/nghuuphuoc/bootstrapvalidator/issues/422): Exclude particular field by ```excluded``` option or ```data-bv-excluded``` attribute
 * [#431](https://github.com/nghuuphuoc/bootstrapvalidator/issues/431): Add built time to the build file

+ 1 - 1
dist/css/bootstrapValidator.min.css

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.0-dev, built on 2014-07-01 8:44:14 AM
+ * @version     v0.5.0-dev, built on 2014-07-01 11:21:31 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 22 - 1
dist/js/bootstrapValidator.js

@@ -2,7 +2,7 @@
  * BootstrapValidator (http://bootstrapvalidator.com)
  * The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
  *
- * @version     v0.5.0-dev, built on 2014-07-01 8:44:14 AM
+ * @version     v0.5.0-dev, built on 2014-07-01 11:21:31 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -786,6 +786,27 @@
                 $(this).data('bv.messages').find('.help-block[data-bv-validator="' + validator + '"][data-bv-for="' + field + '"]').html(message);
             });
         },
+        
+        /**
+         * Update the option of a specific validator
+         * 
+         * @param {String|jQuery} field The field name or field element
+         * @param {String} validator The validator name
+         * @param {String} option The option name
+         * @param {String} value The value to set
+         * @returns {BootstrapValidator}
+         */
+        updateOption: function(field, validator, option, value) {
+            if ('object' === typeof field) {
+                field = field.attr('data-bv-field');
+            }
+            if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
+                this.options.fields[field].validators[validator][option] = value;
+                this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
+            }
+
+            return this;
+        },
 
         /**
          * Update all validating results of field

ファイルの差分が大きいため隠しています
+ 3 - 3
dist/js/bootstrapValidator.min.js


+ 10 - 2
src/js/bootstrapValidator.js

@@ -793,10 +793,18 @@
          * @param {String} validator The validator name
          * @param {String} option The option name
          * @param {String} value The value to set
+         * @returns {BootstrapValidator}
          */
         updateOption: function(field, validator, option, value) {
-            this.options.fields[field].validators[validator][option] = value;
-            this.updateStatus(field, 'NOT_VALIDATED', validator);
+            if ('object' === typeof field) {
+                field = field.attr('data-bv-field');
+            }
+            if (this.options.fields[field] && this.options.fields[field].validators[validator]) {
+                this.options.fields[field].validators[validator][option] = value;
+                this.updateStatus(field, this.STATUS_NOT_VALIDATED, validator);
+            }
+
+            return this;
         },
 
         /**