Browse Source

Coma separator handling in greaterThan and lessThen validators

mgibas 11 years ago
parent
commit
e02fa352f7

+ 2 - 1
.gitignore

@@ -1,3 +1,4 @@
 .idea
 _gh_pages
-node_modules
+node_modules
+bower_components

+ 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.2-dev, built on 2014-09-18 8:09:53 AM
+ * @version     v0.5.2-dev, built on 2014-09-19 6:26:49 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT

+ 7 - 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.2-dev, built on 2014-09-18 8:09:53 AM
+ * @version     v0.5.2-dev, built on 2014-09-19 6:26:49 PM
  * @author      https://twitter.com/nghuuphuoc
  * @copyright   (c) 2013 - 2014 Nguyen Huu Phuoc
  * @license     MIT
@@ -2908,6 +2908,9 @@ if (typeof jQuery === 'undefined') {
             if (value === '') {
                 return true;
             }
+            if (value.indexOf(',') > -1){
+                value = value.replace(',', '.');
+            }
             if (!$.isNumeric(value)) {
                 return false;
             }
@@ -5157,6 +5160,9 @@ if (typeof jQuery === 'undefined') {
             if (value === '') {
                 return true;
             }
+            if (value.indexOf(',') > -1){
+                value = value.replace(',', '.');
+            }
             if (!$.isNumeric(value)) {
                 return false;
             }

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


+ 3 - 0
src/js/validator/greaterThan.js

@@ -44,6 +44,9 @@
             if (value === '') {
                 return true;
             }
+            if (value.indexOf(',') > -1){
+                value = value.replace(',', '.');
+            }
             if (!$.isNumeric(value)) {
                 return false;
             }

+ 3 - 0
src/js/validator/lessThan.js

@@ -44,6 +44,9 @@
             if (value === '') {
                 return true;
             }
+            if (value.indexOf(',') > -1){
+                value = value.replace(',', '.');
+            }
             if (!$.isNumeric(value)) {
                 return false;
             }

+ 22 - 0
test/spec.js

@@ -2827,6 +2827,17 @@ describe('greaterThan', function() {
         expect(this.bv.isValid()).toBeTruthy();
     });
 
+    it('value with coma separator', function() {
+        this.$age.val('10,4');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$age.val('18,678');
+        this.bv.validate();
+        expect(this.bv.isValid()).toBeTruthy();
+    });
+
     it('compare to other field', function() {
         this.$age.attr('data-bv-greaterthan-value', 'minAge');
         this.bv.destroy();
@@ -4475,6 +4486,17 @@ describe('lessThan', function() {
         expect(this.bv.isValid()).toEqual(false);
     });
 
+    it('value with coma separator', function() {
+        this.$age.val('120,2234');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$age.val('30,2234');
+        this.bv.validate();
+        expect(this.bv.isValid()).toBeTruthy();
+    });
+
     it('compare to value', function() {
         this.$age.val(120);
         this.bv.validate();

+ 11 - 0
test/spec/validator/greaterThan.js

@@ -56,6 +56,17 @@ describe('greaterThan', function() {
         expect(this.bv.isValid()).toBeTruthy();
     });
 
+    it('value with coma separator', function() {
+        this.$age.val('10,4');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$age.val('18,678');
+        this.bv.validate();
+        expect(this.bv.isValid()).toBeTruthy();
+    });
+
     it('compare to other field', function() {
         this.$age.attr('data-bv-greaterthan-value', 'minAge');
         this.bv.destroy();

+ 11 - 0
test/spec/validator/lessThan.js

@@ -45,6 +45,17 @@ describe('lessThan', function() {
         expect(this.bv.isValid()).toEqual(false);
     });
 
+    it('value with coma separator', function() {
+        this.$age.val('120,2234');
+        this.bv.validate();
+        expect(this.bv.isValid()).toEqual(false);
+
+        this.bv.resetForm();
+        this.$age.val('30,2234');
+        this.bv.validate();
+        expect(this.bv.isValid()).toBeTruthy();
+    });
+
     it('compare to value', function() {
         this.$age.val(120);
         this.bv.validate();