Browse Source

#991: The field is validated only one time when setting trigger: 'blur', container: 'tooltip'

Phuoc Nguyen 11 years ago
parent
commit
18b2c65567
3 changed files with 145 additions and 0 deletions
  1. 1 0
      CHANGELOG.md
  2. 72 0
      test/spec.js
  3. 72 0
      test/spec/container.js

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ __New Features__
 
 __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'```
 
 __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)

+ 72 - 0
test/spec.js

@@ -266,6 +266,78 @@ describe('container tooltip/popover', function() {
         expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
         expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
     });
+
+    // #991: Validate once when setting trigger: blur, container: tooltip
+    it('trigger: blur, container: tooltip', function() {
+        $('#containerForm').bootstrapValidator({
+            container: 'tooltip',
+            trigger: 'blur',
+            fields: {
+                firstName: {
+                    validators: {
+                        stringLength: {
+                            min: 5,
+                            message: 'The first name must be more than 5 characters'
+                        },
+                        notEmpty: {
+                            message: 'The first name is required'
+                        },
+                        regexp: {
+                            regexp: /^[a-z]+$/i,
+                            message: 'The first name must consist of a-z, A-Z characters only'
+                        }
+                    }
+                },
+                lastName: {
+                    validators: {
+                        stringLength: {
+                            min: 5,
+                            message: 'The last name must be more than 5 characters'
+                        },
+                        notEmpty: {
+                            message: 'The last name is required'
+                        },
+                        regexp: {
+                            regexp: /^[a-z]+$/i,
+                            message: 'The last name must consist of a-z, A-Z characters only'
+                        }
+                    }
+                }
+            }
+        });
+
+        this.bv         = $('#containerForm').data('bootstrapValidator');
+        this.$firstName = this.bv.getFieldElements('firstName');
+        this.$lastName  = this.bv.getFieldElements('lastName');
+
+        this.$firstName.val('').trigger('blur');
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name is required');
+
+        this.bv.resetForm();
+        this.$firstName.val('@not#valid');
+        this.$lastName.val('').focus();
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must consist of a-z, A-Z characters only');
+
+        this.bv.resetForm();
+        this.$firstName.val('Phuo');
+        this.$lastName.val('').focus();
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must be more than 5 characters');
+
+        this.bv.resetForm();
+        this.$firstName.val('Phuoc');
+        this.$lastName.val('').focus();
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
+    });
 });
 
 describe('dynamic fields', function() {

+ 72 - 0
test/spec/container.js

@@ -199,4 +199,76 @@ describe('container tooltip/popover', function() {
         expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
         expect(this.$lastName.parent().find('i').data('bs.popover')).toBeUndefined();
     });
+
+    // #991: Validate once when setting trigger: blur, container: tooltip
+    it('trigger: blur, container: tooltip', function() {
+        $('#containerForm').bootstrapValidator({
+            container: 'tooltip',
+            trigger: 'blur',
+            fields: {
+                firstName: {
+                    validators: {
+                        stringLength: {
+                            min: 5,
+                            message: 'The first name must be more than 5 characters'
+                        },
+                        notEmpty: {
+                            message: 'The first name is required'
+                        },
+                        regexp: {
+                            regexp: /^[a-z]+$/i,
+                            message: 'The first name must consist of a-z, A-Z characters only'
+                        }
+                    }
+                },
+                lastName: {
+                    validators: {
+                        stringLength: {
+                            min: 5,
+                            message: 'The last name must be more than 5 characters'
+                        },
+                        notEmpty: {
+                            message: 'The last name is required'
+                        },
+                        regexp: {
+                            regexp: /^[a-z]+$/i,
+                            message: 'The last name must consist of a-z, A-Z characters only'
+                        }
+                    }
+                }
+            }
+        });
+
+        this.bv         = $('#containerForm').data('bootstrapValidator');
+        this.$firstName = this.bv.getFieldElements('firstName');
+        this.$lastName  = this.bv.getFieldElements('lastName');
+
+        this.$firstName.val('').trigger('blur');
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name is required');
+
+        this.bv.resetForm();
+        this.$firstName.val('@not#valid');
+        this.$lastName.val('').focus();
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must consist of a-z, A-Z characters only');
+
+        this.bv.resetForm();
+        this.$firstName.val('Phuo');
+        this.$lastName.val('').focus();
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeDefined();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').type).toEqual('tooltip');
+        expect(this.$firstName.parent().find('i').data('bs.tooltip').getTitle()).toEqual('The first name must be more than 5 characters');
+
+        this.bv.resetForm();
+        this.$firstName.val('Phuoc');
+        this.$lastName.val('').focus();
+        this.bv.validate();
+        expect(this.$firstName.parent().find('i').data('bs.tooltip')).toBeUndefined();
+    });
 });