Skip to content

Commit

Permalink
fix(br-cep): force cep input to string
Browse files Browse the repository at this point in the history
  • Loading branch information
neokyox committed Mar 24, 2016
1 parent 40d2817 commit 65d64b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/br/cep/cep.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var cepMask = new StringMask('00000-000');

module.exports = maskFactory({
clearValue: function(rawValue) {
return rawValue.replace(/[^0-9]/g, '').slice(0, 8);
return rawValue.toString().replace(/[^0-9]/g, '').slice(0, 8);
},
format: function(cleanValue) {
return (cepMask.apply(cleanValue) || '').replace(/[^0-9]$/, '');
Expand Down
9 changes: 9 additions & 0 deletions src/br/cep/cep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ describe('ui-br-cep-mask', function() {
expect(maskedModel.$formatters.length).toBe(model.$formatters.length + 1);
});

it('should convert number inputs to correct format', function() {
var input = TestUtil.compile('<input ng-model="model" ui-br-cep-mask>', {
model: 30112010
});

var model = input.controller('ngModel');
expect(model.$viewValue).toBe('30112-010');
});

it('should format initial model values', function() {
var input = TestUtil.compile('<input ng-model="model" ui-br-cep-mask>', {
model: '30112010'
Expand Down

0 comments on commit 65d64b1

Please sign in to comment.