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

81
Visualizações
Handling of overlapping events

Have inputs with very complex behavior where for example the change-event regulating any input value formatting like .trim() and the keydown-event where the next focus with .focus() went so if the content changed but also the input is left with enter I get problems cause the behavior of the next focus is based on the correct input formatting before but I cannot control the order or appearance of events.

With this logical and practical overlapping I try multiple solutions and end up blocking any typing by trying block keydown with event.preventDefault to trigger also change or a double code excecution of side effects caused by special input values so how can I control events here when it seems no event does know about the other?!

In general: What should be a code design to handle problems with any overlapping events?

document.getElementById("main").addEventListener("change", function(event){
  console.log("change");
});
document.getElementById("main").addEventListener("keydown", function(event){
  if(event.key == "Enter"){
    console.log("keydown");
  }
});
<ol>
  <li>change and click out => change</li>
  <li>press enter => keydown</li>
  <li>change and press enter => kewdown and change instead change and keydown</li>
</ol>
<input id="main" value="x"/>

about 4 years ago · Juan Pablo Isaza
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