Browse Source

#1014: Fix isValidField and validateField for fields without validators, thanks to @jazzzz

Phuoc Nguyen 11 years ago
parent
commit
65db8ad0da

+ 1 - 0
CHANGELOG.md

@@ -25,6 +25,7 @@ __Improvements__
 __Bug Fixes__
 * [#933](https://github.com/nghuuphuoc/bootstrapvalidator/issues/933), [#959](https://github.com/nghuuphuoc/bootstrapvalidator/issues/959): Tooltip/popover isn't destroyed when the field is valid
 * [#991](https://github.com/nghuuphuoc/bootstrapvalidator/issues/991): The field is validated only one time when setting ```trigger: 'blur'```, ```container: 'tooltip'```
+* [#1014](https://github.com/nghuuphuoc/bootstrapvalidator/pull/1014): Fix [isValidField()](http://bootstrapvalidator.com/api/#is-valid-field) and [validateField()](http://bootstrapvalidator.com/api/#validate-field) methods for fields without validators, thanks to [@jazzzz](https://github.com/jazzzz)
 
 __Document__
 * [#848](https://github.com/nghuuphuoc/bootstrapvalidator/pull/848): Update the [stringLength](http://bootstrapvalidator.com/validators/stringLength) document, thanks to [@Relequestual](https://github.com/Relequestual)

+ 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.3-dev, built on 2014-10-27 8:07:48 AM
+ * @version     v0.5.3-dev, built on 2014-10-28 8:49:13 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 3 - 3
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.3-dev, built on 2014-10-27 8:07:48 AM
+ * @version     v0.5.3-dev, built on 2014-10-28 8:49:13 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -839,7 +839,7 @@ if (typeof jQuery === 'undefined') {
                     break;
             }
 
-            if (fields.length === 0 || (this.options.fields[field] && this.options.fields[field].enabled === false)) {
+            if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
                 return this;
             }
 
@@ -1154,7 +1154,7 @@ if (typeof jQuery === 'undefined') {
                 default:
                     break;
             }
-            if (fields.length === 0 || this.options.fields[field] === null || this.options.fields[field].enabled === false) {
+            if (fields.length === 0 || !this.options.fields[field] || this.options.fields[field].enabled === false) {
                 return true;
             }
 

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


+ 21 - 0
test/spec.js

@@ -17,6 +17,9 @@ describe('api', function() {
                 '<div class="form-group">',
                     '<input type="text" name="email" data-bv-notempty data-bv-emailaddress />',
                 '</div>',
+                '<div class="form-group">',
+                    '<input type="text" name="note"/>',
+                '</div>',
             '</form>'
         ].join('\n')).appendTo('body');
 
@@ -24,6 +27,7 @@ describe('api', function() {
 
         this.bv     = $('#apiForm').data('bootstrapValidator');
         this.$email = this.bv.getFieldElements('email');
+        this.$note  = $('#apiForm').find('input[name="note"]');
     });
 
     afterEach(function() {
@@ -63,6 +67,23 @@ describe('api', function() {
         expect(this.bv.getOptions('username', 'stringLength', 'min')).toEqual('8');
         expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
     });
+
+    // #1014
+    it('isValidField()', function() {
+        this.$email.val('email@domain.com');
+        this.bv.validate();
+        expect(this.bv.isValidField(this.$note)).toBeTruthy();
+        expect(this.bv.isValidField(this.$email)).toBeTruthy();
+    });
+
+    // #1014
+    it('validateField()', function() {
+        this.$email.val('email@domain.com');
+        this.bv.validateField(this.$email);
+        this.bv.validateField(this.$note);
+        expect(this.bv.isValidField(this.$email)).toBeTruthy();
+        expect(this.bv.isValidField(this.$note)).toBeTruthy();
+    });
 });
 
 describe('container form option', function() {

+ 2 - 0
test/spec/api.js

@@ -68,6 +68,7 @@ describe('api', function() {
         expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
     });
 
+    // #1014
     it('isValidField()', function() {
         this.$email.val('email@domain.com');
         this.bv.validate();
@@ -75,6 +76,7 @@ describe('api', function() {
         expect(this.bv.isValidField(this.$email)).toBeTruthy();
     });
 
+    // #1014
     it('validateField()', function() {
         this.$email.val('email@domain.com');
         this.bv.validateField(this.$email);