react-native-masked-text icon indicating copy to clipboard operation
react-native-masked-text copied to clipboard

I can't put a negative value with type money

Open guilhermecampossilva9 opened this issue 4 years ago • 7 comments

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

guilhermecampossilva9 avatar Mar 13 '20 14:03 guilhermecampossilva9

Same, would be great to have this

Ch3my avatar Mar 23 '20 19:03 Ch3my

Same problem.

mcatal avatar Apr 25 '20 11:04 mcatal

Same problem.

resplandeluiz avatar Jun 05 '20 19:06 resplandeluiz

Same problem for me

jailsonpaca avatar Apr 07 '21 11:04 jailsonpaca

I solve with this:

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

jailsonpaca avatar Apr 07 '21 13:04 jailsonpaca

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
}

Solstice1557 avatar Dec 23 '22 11:12 Solstice1557

Are there plans to add ?

JoezerSmaniotto avatar Apr 22 '24 12:04 JoezerSmaniotto