Skip to content

Commit

Permalink
prevent trailing separator for recurring pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbbottam committed Dec 24, 2015
1 parent 9eb0318 commit e10e6e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/auto-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ function formatter(targetNode, separator, separatorIndex, separatorPattern, e) {
}
}

if (this.recurringPattern &&
separator.indexOf(expectedValueArray[expectedValueArray.length - 1]) !== -1) {
expectedValueArray.pop();
}

if (this.direction === 'rtl') {
expectedValueArray.reverse();
}
Expand Down Expand Up @@ -226,6 +231,11 @@ AutoFormatter.format = function(value, format, limitToMaxLength, recurringPatter
}
}

if (recurringPattern &&
separator.indexOf(expectedValueArray[expectedValueArray.length - 1]) !== -1) {
expectedValueArray.pop();
}

if (direction === 'rtl') {
expectedValueArray.reverse();
}
Expand Down
6 changes: 3 additions & 3 deletions test/auto-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ describe('AutoFormatter', function() {

autoFormatter.disableFormatting();
inputNode.setAttribute('data-format', 'XXX,XXX.XX');
inputNode.value = '123456';
inputNode.value = '12345';
autoFormatter = new AutoFormatter(inputNode, false, true, 'rtl');
autoFormatter.enableFormatting();
event.triggerKeyupEvent(inputNode, 48);
assert.equal(inputNode.value, '1,234.56');
assert.equal(inputNode.value, '123.45');
});

});
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('AutoFormatter', function() {

it('should format in rtl manner, recurringly if desired', function() {
assert.equal(AutoFormatter.format('1234567890', 'XXX,XXX.XX', false, true, 'rtl'), '12,345,678.90');
assert.equal(AutoFormatter.format('123456', 'XXX,XXX.XX', false, true, 'rtl'), '1,234.56');
assert.equal(AutoFormatter.format('12345', 'XXX,XXX.XX', false, true, 'rtl'), '123.45');
});

});
Expand Down

0 comments on commit e10e6e9

Please sign in to comment.