Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
How to separate the "press-key" from the "click-mouse" event to prevent submission when press-key?

I have the "chips" form link you can see in the attached image here and I want to create a condition such as if someone press "Enter" he can note the item added but what happens here is that form sends the data to backend.

image description here

I tried many times to modify the behavior using the "event" but it didn't work you can see the approaches I sticked with:

Approach1:

// input to submit job
const submit_job = document.getElementById("submit-job");
submit_job.onclick = (e) => {
    e.preventDefault();
    if (e.key !== "") {
        console.log(e.currentTarget)
    } else if (e.pointerType === "mouse") {
        submit_job.onsubmit = () => {
            return true
        }
    }
}

// This approach won't work because I found that "e.key" worked only when typing by Keyboard

Approach 2:

function getEventType(event) {
    if (event.type === "keydown") {
        event.preventDefault();
    }
}

submit_job.addEventListener('keydown', getEventType, true);

submit_job.addEventListener('click', getEventType);

so, any help in that issue, please?

Note:

No need to see the full code because the code is working fine but when I place it into the form this problem occurs so, you can spire me using that variable only "submit_job" in your answer.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your implementation of the form submission does not seem like a good idea. You should not prevent users from submitting the from when pressing "Enter". Clicking "Enter" should trigger a form submission which is common for most forms. Why not add a unique button beside the input field that when clicked allows the user to enter a note or text? If you take your current approach users will only be able to submit by clicking the submit button which is bad practice. I suggest creating an additional button and adding an event handler to that button so you have a button that adds notes when clicked, so pressing "Enter" will not clash with what you are trying to accomplish.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda