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

84
Vistas
HTML input validity initial state

Let me show some examples so you understand the problem clearly.

✔️ Exemple 1 : working as expected

Consider an input <input required /> and some css to visualize his validity.

console.log( document.querySelector('input').checkValidity() )
input:invalid { background: pink; }
<input required />

If we check it's validity state via Javascript inputEl.checkValidity() we get a false, looking further in inputEl.validity shows { valueMissing: true, typeMismatch: false, …}

Ok everything is logic for now.

✔️ Exemple 2 : working as expected

Now if we add a value to the input, validation should be fine :

console.log( document.querySelector('input').checkValidity() )
input:invalid { background: pink; }
<input required value="John Cena" />

If we check it's validity state via Javascript inputEl.checkValidity() we get a true.

Make sense.

❌ Exemple 3 : not working as expected

Let's add maxlength="5" :

console.log( document.querySelector('input').checkValidity() )
input:invalid { background: pink; }
<input required value="John Cena" maxlength="5" />

Why is the field not invalid initially ?

If we check it's validity state via Javascript inputEl.checkValidity() we get a true ... ?

Also if we edit this input, then the validation will be updated and the field will be marked as invalid.

Here is the full exemple : https://codepen.io/Shuunen/pen/XWaqpVo

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