bhrott / react-native-masked-text

A pure javascript masked text and input text component for React-Native.
MIT License
1.6k stars 251 forks source link

I can't put a negative value with type money #218

Open guilhermecampossilva9 opened 4 years ago

guilhermecampossilva9 commented 4 years ago

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

Ch3my commented 4 years ago

Same, would be great to have this

mcatal commented 4 years ago

Same problem.

resplandeluiz commented 4 years ago

Same problem.

jailsonpaca commented 3 years ago

Same problem for me

jailsonpaca commented 3 years ago

I solve with this:

<TextInputMask type="custom", options={{ mask: "*99999", translation: { "9": (val: string) => (val === "-" ? "" : val) }, }} />

Solstice1557 commented 1 year ago

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
}
JoezerSmaniotto commented 5 months ago

Are there plans to add ?