Skip to content

Commit dae0777

Browse files
committed
fix: fix can not receive zero as decimal when allowDecimal is true
1 parent 5423e29 commit dae0777

8 files changed

+34
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
<a name="1.0.4"></a>
2+
## [v1.0.4](https://github.com/changLiuUNSW/angular-numeric-input/compare/1.0.3...1.0.4) (2017-05-28)
3+
4+
### Fixed
5+
6+
- fix can not receive zero as decimal when allowDecimal is true closes [#3](https://github.com/changLiuUNSW/angular-numeric-input/issues/3)
7+
18
<a name="1.0.3"></a>
29
## [v1.0.3](https://github.com/changLiuUNSW/angular-numeric-input/compare/1.0.2...1.0.3) (2016-12-2)
310

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"homepage": "https://github.com/changLiuUNSW/angular-numeric-input",
44
"author": "Chang Liu <[email protected]>",
55
"description": "AngularJS directive to provide real-time number formatting and validations",
6-
"version": "1.0.3",
6+
"version": "1.0.4",
77
"main": [
88
"dist/angular-numeric-input.js"
99
],

dist/angular-numeric-input.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
max,
1313
lastValidValue,
1414
dotSuffix,
15+
firstDecimalZero,
1516
positiveInteger = true,
1617
minNotEqual,
1718
maxNotEqual,
@@ -122,6 +123,8 @@
122123
value = '0' + value;
123124
}
124125

126+
firstDecimalZero = /\d*\.0$/.test(value);
127+
125128
var empty = ngModelCtrl.$isEmpty(value);
126129
if (empty || (NUMBER_REGEXP.test(value) && numberLength(value) <= maxLength)) {
127130
lastValidValue = (value === '') ? null : (empty ? value : round(value));
@@ -166,6 +169,9 @@
166169
if (!positiveInteger && dotSuffix) {
167170
viewValue += '.';
168171
}
172+
if (!positiveInteger && firstDecimalZero) {
173+
viewValue += '.0';
174+
}
169175
//This logic is used to preserve cursor position after formatting
170176
var start = el[0].selectionStart,
171177
end = el[0].selectionEnd,

dist/angular-numeric-input.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-numeric-input.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-numeric-input",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "AngularJS directive to provide real-time number formatting and validations",
55
"main": "./index.js",
66
"scripts": {

src/angular-numeric-input.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
max,
1313
lastValidValue,
1414
dotSuffix,
15+
firstDecimalZero,
1516
positiveInteger = true,
1617
minNotEqual,
1718
maxNotEqual,
@@ -122,6 +123,8 @@
122123
value = '0' + value;
123124
}
124125

126+
firstDecimalZero = /\d*\.0$/.test(value);
127+
125128
var empty = ngModelCtrl.$isEmpty(value);
126129
if (empty || (NUMBER_REGEXP.test(value) && numberLength(value) <= maxLength)) {
127130
lastValidValue = (value === '') ? null : (empty ? value : round(value));
@@ -166,6 +169,9 @@
166169
if (!positiveInteger && dotSuffix) {
167170
viewValue += '.';
168171
}
172+
if (!positiveInteger && firstDecimalZero) {
173+
viewValue += '.0';
174+
}
169175
//This logic is used to preserve cursor position after formatting
170176
var start = el[0].selectionStart,
171177
end = el[0].selectionEnd,

test/angular-numeric-input.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,17 @@ describe('numericInput: test spec', function() {
174174
expect(inputElement.val()).toEqual('1,234.5');
175175
});
176176

177+
it('test for allow decimal config: input 1234.05 should be auto-formatting to 1,234.05', function() {
178+
initAllowDecimal();
179+
180+
inputElement.val('1234.05');
181+
inputElement.triggerHandler('input');
182+
183+
var ngModel = inputElement.controller('ngModel');
184+
expect(ngModel.$viewValue).toEqual('1,234.05');
185+
expect(inputElement.val()).toEqual('1,234.05');
186+
});
187+
177188
it('test for allow decimal config: input 1234.567 should be auto-formatting to 1,234.57', function() {
178189
initAllowDecimal();
179190

0 commit comments

Comments
 (0)