Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
wrong behaviour of number format

So I'm using the NumberFormat library for building a placeholder, but it doesn't work how I wanted it to work, and I don't find the reason. The behavior of the input field is quite strange. The "$0" which should behave as a placeholder behaves as a character, so if the user types "120", the amount will actually be "1200".

Here's a video of how it works: https://media.giphy.com/media/sptBQiYqQr3B54rJFu/giphy.gif

But the correct behaviour would be to, when there is a 0, and the user inputs a value, the 0 should be replaced (you can check the google calculator, it does that).

<NumberFormat
                defaultValue={undefined}
                value={payoutInputValue}
                displayType="input"
                thousandSeparator
                decimalScale={2}
                prefix={getCurrencySymbol(currency)}
                allowLeadingZeros={false}
                allowNegative={false}
                getInputRef={numberInputRef}
                onValueChange={(values) =>
                  setPayoutInputValue(values?.floatValue || undefined)
                }
                disabled={disabled || isLoading}
                isAllowed={isDrawAmountAllowed(0, currency)}
                required
              />

and the setPayoutInputValue function:

const [payoutInputValue, setPayoutInputValue] = useState<number>(
    payout === 0 && isAmountParamValid ? amountParamParsed : payout
  );

I have not much experience with React, so if you could answer with basic terms, that'd be awesome. Thanks!

EDIT: managed to make it work! added placeholder attribute and value={undefined}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try setting the hintText prop for NumberFormat, also give as an initial value undefined.

<NumberFormat
  hintText="Some placeholder"
  value={this.state.card}
  customInput={TextField}
  format="#### #### #### ####"
/>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda