Skip to content

Commit

Permalink
fix(#96): cel-phone mask change issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-hur Santos Ott committed Oct 7, 2018
1 parent 3325156 commit a072791
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- [#95](https://github.com/benhurott/react-native-masked-text/issues/95): Number value cause errors into only-numbers mask (thanks to [dfsilva](https://github.com/dfsilva) for reporting)
- [#96](https://github.com/benhurott/react-native-masked-text/issues/96): cel-phone mask is not changing properly. (thanks to [jgfidelis](https://github.com/jgfidelis) for reporting)

## [1.9.1] - 2018-09-09

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
copy-to-test:
rm -rf ../rn-test/react-native-masked-text
npm run clean
npm run build
cp -R dist ../rn-test/react-native-masked-text
10 changes: 9 additions & 1 deletion __tests__/mask/cel-phone.mask.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,18 @@ test('getMask for 99888877776 returns (99) 99999-9999', () => {
expect(received).toBe(expected)
})

test('getMask for 999998888 withoud DDD returns 99999-9999', () => {
test('getMask for 999998888 without DDD returns 99999-9999', () => {
var mask = new CelPhoneMask()
var expected = '99999-9999'
var received = mask.getMask('999998888', { withDDD: false })

expect(received).toBe(expected)
})

test('getValue for (12) 1234-56789 must return (12) 12345-6789', () => {
var mask = new CelPhoneMask()
var expected = '(12) 12345-6789'
var received = mask.getValue('(12) 1234-56789')

expect(received).toBe(expected)
})
2 changes: 1 addition & 1 deletion dist/lib/masks/cel-phone.mask.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/lib/masks/only-numbers.mask.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/masks/cel-phone.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ export default class CelPhoneMask extends BaseMask {
}

getValue(value, settings) {
let mask = this.getMask(value, settings)
return CustomMask.shared.getValue(value, { mask })
let cleanedValue = super.removeNotNumbers(value)
let mask = this.getMask(cleanedValue, settings)
return CustomMask.shared.getValue(cleanedValue, { mask })
}

getRawValue(maskedValue, settings) {
Expand Down

0 comments on commit a072791

Please sign in to comment.