react-native-masked-text
react-native-masked-text copied to clipboard
I can't put a negative value with type money
I'm trying to enter a negative number for the field with the money mask and I can't. Could have support for typing the minus sign
Same, would be great to have this
Same problem.
Same problem.
Same problem for me
I solve with this:
<TextInputMask type="custom", options={{ mask: "*99999", translation: { "9": (val: string) => (val === "-" ? "" : val) }, }} />
my dirty hack to enable that functionality
import * as Masks from 'react-native-masked-text/dist/lib/masks'
const oldValue: (value: string, settings: TextInputMaskOptionProp) => string =
Masks.MoneyMask.prototype.getValue
Masks.MoneyMask.prototype.getValue = function (
value: string,
settings: TextInputMaskOptionProp,
) {
const isNegative = value.indexOf('-') >= 0
const appliedValue = oldValue.apply(this, [value, settings])
if (!isNegative || !appliedValue || appliedValue.indexOf('-') >= 0) {
return appliedValue
}
if (appliedValue.startsWith('$')) {
return '$-' + appliedValue.substring(1)
}
return '-' + appliedValue
}
Are there plans to add ?