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

141
Visualizações
The definitive way to append a unit to your number input

👋 Hi community!

What would be the proper way to add a unit inside a number input?

The goal is not to add a span with a negative left margin to come over the input, but to really insert a non-editable unit directly after the number, adapting to the number length:

[....3€....]
[...333€...]
[..33333€..]

I've found this calculator to achieve this result quite elegantly, but can't figure how to get the same effect.

Any ideas? 🙏

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

0

First of all Don't use input of a type number for this one because it will not allow you to use currency symbol.

Now, create an input and listen for keypress. If it's a number or minus sign or a dot intert it before the symbol.

input.addEventListener('keypressed', event => {
  const codes = [] // check the codes here https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
  if (codes.includes(event.key)) return
  input.value = input.value.slice(0, -1) + event.key // probably some mapping needed
})

The code above is an untested proof of concept

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