Browse Source

#425: Custom trigger event is ignored by field validators

phuoc 11 years ago
parent
commit
bc8c0994f9

+ 1 - 0
CHANGELOG.md

@@ -73,6 +73,7 @@ __Bug Fixes__
 * [#401](https://github.com/nghuuphuoc/bootstrapvalidator/issues/401): [stringLength validator](http://bootstrapvalidator.com/validators/stringLength/) allows spaces after max length
 * [#411](https://github.com/nghuuphuoc/bootstrapvalidator/pull/411): Fix the [ean validator](http://bootstrapvalidator.com/validators/ean/) when the check digit is zero, thanks to [@manish-in-java](https://github.com/manish-in-java)
 * [#417](https://github.com/nghuuphuoc/bootstrapvalidator/issues/417): IPv6 validator doesn't work
+* [#425](https://github.com/nghuuphuoc/bootstrapvalidator/issues/425): Custom trigger event is ignored by field validators
 * [#447](https://github.com/nghuuphuoc/bootstrapvalidator/pull/447): Skip the ```_isExcluded()``` when initializing the form. This fixes [#269](https://github.com/nghuuphuoc/bootstrapvalidator/issues/269), [#273](https://github.com/nghuuphuoc/bootstrapvalidator/issues/273). Thanks to [@AlaskanShade](https://github.com/AlaskanShade)
 
 __Document__

+ 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-06 10:11:03 AM
+ * @version     v0.5.0-dev, built on 2014-07-06 9:40:56 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 10 - 7
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-06 10:11:03 AM
+ * @version     v0.5.0-dev, built on 2014-07-06 9:40:56 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -230,7 +230,11 @@
                 total     = fields.length,
                 type      = fields.attr('type'),
                 updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
-                event     = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent;
+                event     = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent,
+                trigger   = (this.options.fields[field].trigger || this.options.trigger || event).split(' '),
+                events    = $.map(trigger, function(item) {
+                    return item + '.update.bv';
+                }).join(' ');
 
             for (var i = 0; i < total; i++) {
                 var $field    = fields.eq(i),
@@ -249,7 +253,7 @@
                 $parent.find('i[data-bv-icon-for="' + field + '"]').remove();
 
                 // Whenever the user change the field value, mark it as not validated yet
-                $field.off(event + '.update.bv').on(event + '.update.bv', function() {
+                $field.off(events).on(events, function() {
                     // Reset the flag
                     that._submitIfValid = false;
                     that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
@@ -316,10 +320,9 @@
             }
 
             // Set live mode
-            var trigger = this.options.fields[field].trigger || this.options.trigger || event,
-                events  = $.map(trigger.split(' '), function(item) {
-                    return item + '.live.bv';
-                }).join(' ');
+            events = $.map(trigger, function(item) {
+                return item + '.live.bv';
+            }).join(' ');
             switch (this.options.live) {
                 case 'submitted':
                     break;

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


+ 9 - 6
src/js/bootstrapValidator.js

@@ -229,7 +229,11 @@
                 total     = fields.length,
                 type      = fields.attr('type'),
                 updateAll = (total === 1) || ('radio' === type) || ('checkbox' === type),
-                event     = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent;
+                event     = ('radio' === type || 'checkbox' === type || 'file' === type || 'SELECT' === fields.eq(0).get(0).tagName) ? 'change' : this._changeEvent,
+                trigger   = (this.options.fields[field].trigger || this.options.trigger || event).split(' '),
+                events    = $.map(trigger, function(item) {
+                    return item + '.update.bv';
+                }).join(' ');
 
             for (var i = 0; i < total; i++) {
                 var $field    = fields.eq(i),
@@ -248,7 +252,7 @@
                 $parent.find('i[data-bv-icon-for="' + field + '"]').remove();
 
                 // Whenever the user change the field value, mark it as not validated yet
-                $field.off(event + '.update.bv').on(event + '.update.bv', function() {
+                $field.off(events).on(events, function() {
                     // Reset the flag
                     that._submitIfValid = false;
                     that.updateStatus($(this), that.STATUS_NOT_VALIDATED);
@@ -315,10 +319,9 @@
             }
 
             // Set live mode
-            var trigger = this.options.fields[field].trigger || this.options.trigger || event,
-                events  = $.map(trigger.split(' '), function(item) {
-                    return item + '.live.bv';
-                }).join(' ');
+            events = $.map(trigger, function(item) {
+                return item + '.live.bv';
+            }).join(' ');
             switch (this.options.live) {
                 case 'submitted':
                     break;