From 6e62f860fa8a7e194b813a7ae138f012752b4bb9 Mon Sep 17 00:00:00 2001 From: Ben-hur Santos Ott Date: Fri, 16 Jun 2017 22:53:15 -0300 Subject: [PATCH] fix 29 --- README.md | 4 ++++ lib/base-text-component.js | 5 ++++- lib/masks/money.mask.js | 17 +++++++++++++++-- package.json | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index efc01d0a..44317603 100644 --- a/README.md +++ b/README.md @@ -350,6 +350,10 @@ var money = MaskService.toMask('money', '123', { # Changelog +## 1.5.3 +* Fix suffix backspace (thanks to [Thomas Kekeisen](https://github.com/blaues0cke)) +* Fix last character on custom mask (thanks to [Daniel Maly](https://github.com/DanielMaly)) + ## 1.5.2 * Adding `keyboardType` to custom mask. (thanks to [Nurbek Abulgazin](https://github.com/nurbek-ab)) diff --git a/lib/base-text-component.js b/lib/base-text-component.js index dee18f09..054cbe91 100644 --- a/lib/base-text-component.js +++ b/lib/base-text-component.js @@ -91,9 +91,12 @@ export default class BaseTextComponent extends Component { } _getMaskedValue(value) { + let oldValue = this.state.value; + return this._maskHandler.getValue( this._getDefaultValue(value), - this.state.options); + this.state.options, + oldValue); } _getDefaultValue(value) { diff --git a/lib/masks/money.mask.js b/lib/masks/money.mask.js index 0d3d9108..324192be 100644 --- a/lib/masks/money.mask.js +++ b/lib/masks/money.mask.js @@ -14,9 +14,22 @@ export default class MoneyMask extends BaseMask { return 'money'; } - getValue(value, settings) { + getValue(value, settings, oldValue) { let mergedSettings = super.mergeSettings(MONEY_MASK_SETTINGS, settings); - return this.getVMasker().toMoney(value, mergedSettings); + + if (mergedSettings.suffixUnit && oldValue && value) { + // value: 123 R + // oldValue: 123 R$ + + if (value.length == oldValue.length - 1) { + let cleared = this.removeNotNumbers(value); + value = cleared.substr(0, cleared.length - 1); + } + } + + let masked = this.getVMasker().toMoney(value, mergedSettings); + + return masked; } getRawValue(maskedValue, settings) { diff --git a/package.json b/package.json index 6c6c60bc..10c394bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-masked-text", - "version": "1.5.2", + "version": "1.5.3", "description": "Text and TextInput with mask for React Native applications", "main": "index.js", "scripts": {