Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

207
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!