Skip to content

Commit

Permalink
Coma separator handling in greaterThan and lessThen validators
Browse files Browse the repository at this point in the history
  • Loading branch information
mgibas committed Sep 19, 2014
1 parent 875194d commit e02fa35
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
_gh_pages
node_modules
node_modules
bower_components
2 changes: 1 addition & 1 deletion dist/css/bootstrapValidator.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion dist/js/bootstrapValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2908,6 +2908,9 @@ if (typeof jQuery === 'undefined') {
if (value === '') {
return true;
}
if (value.indexOf(',') > -1){
value = value.replace(',', '.');
}
if (!$.isNumeric(value)) {
return false;
}
Expand Down Expand Up @@ -5157,6 +5160,9 @@ if (typeof jQuery === 'undefined') {
if (value === '') {
return true;
}
if (value.indexOf(',') > -1){
value = value.replace(',', '.');
}
if (!$.isNumeric(value)) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions dist/js/bootstrapValidator.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/js/validator/greaterThan.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
if (value === '') {
return true;
}
if (value.indexOf(',') > -1){
value = value.replace(',', '.');
}
if (!$.isNumeric(value)) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/js/validator/lessThan.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
if (value === '') {
return true;
}
if (value.indexOf(',') > -1){
value = value.replace(',', '.');
}
if (!$.isNumeric(value)) {
return false;
}
Expand Down
22 changes: 22 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions test/spec/validator/greaterThan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions test/spec/validator/lessThan.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit e02fa35

Please sign in to comment.