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

143
Views
Does the event `invalid` only fire once?

I tried to hook into the invalid event for numeric input (which is required), and while the invalid event fires right on loading the page (as all the cells are empty), it does not refire if one fills an input field and removes its content or inputs a letter instead of a number. But I could not find anything indicating that this would be its behaviour. But at the same time I can also not find an issue with my code. So I guess I am first asking what the desired behaviour is before I continue hunting for bugs.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As specified in the documentation:

When a form is submitted, invalid events are fired at each form control that is invalid

So when a form is submitted, any input that doesn't adhere to it's constraints, will fire an invalid event.

Here the input is numeric and requires a min of 1. Setting it to 0 and submitting will trigger the invalid event.

document.querySelector('input[type="number"]').addEventListener('invalid', () => {
  console.log('invalid')
})
<form action="#">
  <input type="number" min="1" value="0">
  <input type="submit">
</form>

about 4 years ago · Juan Pablo Isaza Report

0

Apparently rubber ducking is quite helpful:

The invalid event only fires on form submission, while the css :invalid styling is applied live on input events rather than only after submission events.

If a form is submitted with an invalid value, the submittable elements are checked and, if an error is found, the invalid event will fire

https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/invalid_event

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!