Browse Source

Merge remote-tracking branch 'origin/master'

phuoc 11 years ago
parent
commit
486fba498f

+ 1 - 0
CHANGELOG.md

@@ -53,6 +53,7 @@ __Improvements__
 * [#431](https://github.com/nghuuphuoc/bootstrapvalidator/issues/431): Add built time to the build file
 * [#432](https://github.com/nghuuphuoc/bootstrapvalidator/issues/432): Define the callback via ```data-bv-callback-callback``` attribute
 * [#447](https://github.com/nghuuphuoc/bootstrapvalidator/pull/447): [zipCode validator](http://bootstrapvalidator.com/validators/zipCode/) allow to set the country code via another field or callback, thanks to [@AlaskanShade](https://github.com/AlaskanShade)
+* [#451](https://github.com/nghuuphuoc/bootstrapvalidator/pull/451): Validation of numeric fields with decimal steps, thanks to [@Azuka](https://github.com/Azuka)
 * [#456](https://github.com/nghuuphuoc/bootstrapvalidator/issues/456): Adjust the feedback icon position for ```.input-group``` element
 * [#465](https://github.com/nghuuphuoc/bootstrapvalidator/issues/465): Support dynamic message
 

+ 41 - 0
CONTRIBUTORS.md

@@ -0,0 +1,41 @@
+# Contributors
+
+I would like to give big thanks to the following contributors:
+
+* [@aca02djr](https://github.com/aca02djr)
+* [@adgrafik](https://github.com/adgrafik)
+* [@AlaskanShade](https://github.com/AlaskanShade)
+* [@alavers](https://github.com/alavers)
+* [@Azuka](https://github.com/Azuka)
+* [@easonhan007](https://github.com/easonhan007)
+* [@emilchristensen](https://github.com/emilchristensen)
+* [@ericnakagawa](https://github.com/ericnakagawa)
+* [@evilchili](https://github.com/evilchili)
+* [@Francismori7](https://github.com/Francismori7)
+* [@gercheq](https://github.com/gercheq)
+* [@henningda](https://github.com/henningda)
+* [@ikanedo](https://github.com/ikanedo)
+* [@iplus](https://github.com/iplus)
+* [@jcnmulio](https://github.com/jcnmulio)
+* [@jjshoe](https://github.com/jjshoe)
+* [@johanronn77](https://github.com/johanronn77)
+* [@jswale](https://github.com/jswale)
+* [@jzhang6](https://github.com/jzhang6)
+* [@khangvm53](https://github.com/khangvm53)
+* [@kristian-puccio](https://github.com/kristian-puccio)
+* [@lloydde](https://github.com/lloydde)
+* [@manish-in-java](https://github.com/manish-in-java)
+* [@MartinDevillers](https://github.com/MartinDevillers)
+* [@mike1e](https://github.com/mike1e)
+* [@MrC0mm0n](https://github.com/MrC0mm0n)
+* [@mrpollo](https://github.com/mrpollo)
+* [@narutosanjiv](https://github.com/narutosanjiv)
+* [@nathanrosspowell](https://github.com/nathanrosspowell)
+* [@patmoore](https://github.com/patmoore)
+* [@phillprice](https://github.com/phillprice)
+* [@smeagol74](https://github.com/smeagol74)
+* [@thisisclement](https://github.com/thisisclement)
+* [@tiagofontella](https://github.com/tiagofontella)
+* [@tomByrer](https://github.com/tomByrer)
+* [@vaz](https://github.com/vaz)
+* ... might be you! Let's [fork](https://github.com/nghuuphuoc/bootstrapvalidator/fork) and pull a request!

+ 1 - 42
README.md

@@ -105,48 +105,7 @@ The __BootstrapValidator__ plugin is written by Nguyen Huu Phuoc, aka @nghuuphuo
 * [http://twitter.com/nghuuphuoc](http://twitter.com/nghuuphuoc)
 * [http://github.com/nghuuphuoc](http://github.com/nghuuphuoc)
 
-Big thanks to the contributors:
-
-* [@aca02djr](https://github.com/aca02djr)
-* [@adgrafik](https://github.com/adgrafik)
-* [@AlaskanShade](https://github.com/AlaskanShade)
-* [@alavers](https://github.com/alavers)
-* [@easonhan007](https://github.com/easonhan007)
-* [@emilchristensen](https://github.com/emilchristensen)
-* [@ericnakagawa](https://github.com/ericnakagawa)
-* [@evilchili](https://github.com/evilchili)
-* [@Francismori7](https://github.com/Francismori7)
-* [@gercheq](https://github.com/gercheq)
-* [@henningda](https://github.com/henningda)
-* [@ikanedo](https://github.com/ikanedo)
-* [@iplus](https://github.com/iplus)
-* [@jcnmulio](https://github.com/jcnmulio)
-* [@jjshoe](https://github.com/jjshoe)
-* [@johanronn77](https://github.com/johanronn77)
-* [@jswale](https://github.com/jswale)
-* [@jzhang6](https://github.com/jzhang6)
-* [@khangvm53](https://github.com/khangvm53)
-* [@kristian-puccio](https://github.com/kristian-puccio)
-* [@lloydde](https://github.com/lloydde)
-* [@manish-in-java](https://github.com/manish-in-java)
-* [@MartinDevillers](https://github.com/MartinDevillers)
-* [@mike1e](https://github.com/mike1e)
-* [@MrC0mm0n](https://github.com/MrC0mm0n)
-* [@mrpollo](https://github.com/mrpollo)
-* [@narutosanjiv](https://github.com/narutosanjiv)
-* [@nathanrosspowell](https://github.com/nathanrosspowell)
-* [@patmoore](https://github.com/patmoore)
-* [@phillprice](https://github.com/phillprice)
-* [@smeagol74](https://github.com/smeagol74)
-* [@thisisclement](https://github.com/thisisclement)
-* [@tiagofontella](https://github.com/tiagofontella)
-* [@tomByrer](https://github.com/tomByrer)
-* [@vaz](https://github.com/vaz)
-* ... might be you! Let's [fork](https://github.com/nghuuphuoc/bootstrapvalidator/fork) and pull a request!
-
-> If you submit new RegEx, please build it using [RegExr.com](http://regexr.com/), add several tests that pass and fail there,
-> and include the "share" link in your JS as a ```// ``` comment.
-> For example: ```// Test: http://regexr.com/38mqi```
+Big thanks to the [contributors](CONTRIBUTORS.md).
 
 ## License
 

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

+ 36 - 2
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-08 4:05:10 PM
+ * @version     v0.5.0-dev, built on 2014-07-09 10:07:03 AM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -1158,6 +1158,36 @@
         },
 
         /**
+         * Get the field options
+         *
+         * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
+         * @param {String} [validator] The name of validator. It null, the method returns form options
+         * @param {String} [option] The option name
+         * @return {String|Object}
+         */
+        getOptions: function(field, validator, option) {
+            if (!field) {
+                return this.options;
+            }
+            if ('object' === typeof field) {
+                field = field.attr('data-bv-field');
+            }
+            if (!this.options.fields[field]) {
+                return null;
+            }
+
+            var options = this.options.fields[field];
+            if (!validator) {
+                return options;
+            }
+            if (!options.validators || !options.validators[validator]) {
+                return null;
+            }
+
+            return option ? options.validators[validator][option] : options.validators[validator];
+        },
+
+        /**
          * Update the option of a specific validator
          *
          * @param {String|jQuery} field The field name or field element
@@ -3875,7 +3905,7 @@
 
     $.fn.bootstrapValidator.validators.integer = {
         enableByHtml5: function($field) {
-            return ('number' === $field.attr('type'));
+            return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
         },
 
         /**
@@ -4323,6 +4353,10 @@
             separator: 'separator'
         },
 
+        enableByHtml5: function($field) {
+            return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
+        },
+
         /**
          * Validate decimal number
          *

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


+ 30 - 0
src/js/bootstrapValidator.js

@@ -1157,6 +1157,36 @@
         },
 
         /**
+         * Get the field options
+         *
+         * @param {String|jQuery} [field] The field name or field element. If it is not set, the method returns the form options
+         * @param {String} [validator] The name of validator. It null, the method returns form options
+         * @param {String} [option] The option name
+         * @return {String|Object}
+         */
+        getOptions: function(field, validator, option) {
+            if (!field) {
+                return this.options;
+            }
+            if ('object' === typeof field) {
+                field = field.attr('data-bv-field');
+            }
+            if (!this.options.fields[field]) {
+                return null;
+            }
+
+            var options = this.options.fields[field];
+            if (!validator) {
+                return options;
+            }
+            if (!options.validators || !options.validators[validator]) {
+                return null;
+            }
+
+            return option ? options.validators[validator][option] : options.validators[validator];
+        },
+
+        /**
          * Update the option of a specific validator
          *
          * @param {String|jQuery} field The field name or field element

+ 1 - 1
src/js/validator/integer.js

@@ -5,7 +5,7 @@
 
     $.fn.bootstrapValidator.validators.integer = {
         enableByHtml5: function($field) {
-            return ('number' === $field.attr('type'));
+            return ('number' === $field.attr('type')) && ($field.attr('step') === undefined || $field.attr('step') % 1 === 0);
         },
 
         /**

+ 4 - 0
src/js/validator/numeric.js

@@ -9,6 +9,10 @@
             separator: 'separator'
         },
 
+        enableByHtml5: function($field) {
+            return ('number' === $field.attr('type')) && ($field.attr('step') !== undefined) && ($field.attr('step') % 1 !== 0);
+        },
+
         /**
          * Validate decimal number
          *

+ 24 - 13
test/spec.js

@@ -10,16 +10,14 @@ describe('api', function() {
 
     beforeEach(function() {
         $([
-            '<div class="container">',
-                '<form class="form-horizontal" id="apiForm">',
-                    '<div class="form-group">',
-                        '<input type="text" name="username" data-bv-notempty />',
-                    '</div>',
-                    '<div class="form-group">',
-                        '<input type="text" name="email" data-bv-emailaddress />',
-                    '</div>',
-                '</form>',
-            '</div>'
+            '<form class="form-horizontal" id="apiForm">',
+                '<div class="form-group">',
+                    '<input type="text" name="username" data-bv-notempty data-bv-stringlength data-bv-stringlength-min="8" />',
+                '</div>',
+                '<div class="form-group">',
+                    '<input type="text" name="email" data-bv-notempty data-bv-emailaddress />',
+                '</div>',
+            '</form>'
         ].join('\n')).appendTo('body');
 
         $('#apiForm').bootstrapValidator();
@@ -29,10 +27,10 @@ describe('api', function() {
     });
 
     afterEach(function() {
-        $('#apiForm').bootstrapValidator('destroy').parent().remove();
+        $('#apiForm').bootstrapValidator('destroy').remove();
     });
 
-    it('call revalidateField()', function() {
+    it('revalidateField()', function() {
         this.$email.val('email@domain.com');
         this.bv.validate();
         expect(this.bv.isValidField('email')).toBeTruthy();
@@ -42,7 +40,7 @@ describe('api', function() {
         expect(this.bv.isValidField(this.$email)).toEqual(false);
     });
 
-    it('call destroy()', function() {
+    it('destroy()', function() {
         this.bv.destroy();
         expect($('#apiForm').data('bootstrapValidator')).toBeUndefined();
         expect($('#apiForm').find('i[data-bv-icon-for]').length).toEqual(0);
@@ -52,6 +50,19 @@ describe('api', function() {
         expect($('#apiForm').find('.has-error').length).toEqual(0);
         expect($('#apiForm').find('[data-bv-field]').length).toEqual(0);
     });
+
+    it('getOptions()', function() {
+        // Form options
+        expect(this.bv.getOptions().feedbackIcons.valid).toEqual('glyphicon glyphicon-ok');
+
+        // Field options
+        expect(this.bv.getOptions('username', 'stringlength')).toBeNull();
+        expect(this.bv.getOptions('username', 'stringlength', 'min')).toBeNull();
+
+        expect(this.bv.getOptions('username', 'stringLength')).toBeDefined();
+        expect(this.bv.getOptions('username', 'stringLength', 'min')).toEqual('8');
+        expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
+    });
 });
 
 describe('container form option', function() {

+ 24 - 13
test/spec/api.js

@@ -10,16 +10,14 @@ describe('api', function() {
 
     beforeEach(function() {
         $([
-            '<div class="container">',
-                '<form class="form-horizontal" id="apiForm">',
-                    '<div class="form-group">',
-                        '<input type="text" name="username" data-bv-notempty />',
-                    '</div>',
-                    '<div class="form-group">',
-                        '<input type="text" name="email" data-bv-emailaddress />',
-                    '</div>',
-                '</form>',
-            '</div>'
+            '<form class="form-horizontal" id="apiForm">',
+                '<div class="form-group">',
+                    '<input type="text" name="username" data-bv-notempty data-bv-stringlength data-bv-stringlength-min="8" />',
+                '</div>',
+                '<div class="form-group">',
+                    '<input type="text" name="email" data-bv-notempty data-bv-emailaddress />',
+                '</div>',
+            '</form>'
         ].join('\n')).appendTo('body');
 
         $('#apiForm').bootstrapValidator();
@@ -29,10 +27,10 @@ describe('api', function() {
     });
 
     afterEach(function() {
-        $('#apiForm').bootstrapValidator('destroy').parent().remove();
+        $('#apiForm').bootstrapValidator('destroy').remove();
     });
 
-    it('call revalidateField()', function() {
+    it('revalidateField()', function() {
         this.$email.val('email@domain.com');
         this.bv.validate();
         expect(this.bv.isValidField('email')).toBeTruthy();
@@ -42,7 +40,7 @@ describe('api', function() {
         expect(this.bv.isValidField(this.$email)).toEqual(false);
     });
 
-    it('call destroy()', function() {
+    it('destroy()', function() {
         this.bv.destroy();
         expect($('#apiForm').data('bootstrapValidator')).toBeUndefined();
         expect($('#apiForm').find('i[data-bv-icon-for]').length).toEqual(0);
@@ -52,4 +50,17 @@ describe('api', function() {
         expect($('#apiForm').find('.has-error').length).toEqual(0);
         expect($('#apiForm').find('[data-bv-field]').length).toEqual(0);
     });
+
+    it('getOptions()', function() {
+        // Form options
+        expect(this.bv.getOptions().feedbackIcons.valid).toEqual('glyphicon glyphicon-ok');
+
+        // Field options
+        expect(this.bv.getOptions('username', 'stringlength')).toBeNull();
+        expect(this.bv.getOptions('username', 'stringlength', 'min')).toBeNull();
+
+        expect(this.bv.getOptions('username', 'stringLength')).toBeDefined();
+        expect(this.bv.getOptions('username', 'stringLength', 'min')).toEqual('8');
+        expect(this.bv.getOptions('username', 'stringlength', 'max')).toBeNull();
+    });
 });