Skip to content

Commit

Permalink
fix 29
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-hur Santos Ott committed Jun 17, 2017
1 parent 4f88b7b commit 6e62f86
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 4 additions & 1 deletion lib/base-text-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
17 changes: 15 additions & 2 deletions lib/masks/money.mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 6e62f86

Please sign in to comment.