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": {