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

168
Vistas
jQuery val or javascript changing value, validate the field even if the value don't match with the Validation Properties

Element Example:

<textarea class="form-control" id="presentation" required="" minlength="10" maxlength="300"></textarea>

If manually, insert any text, the validation is set to Valid if the length is between 10 and 300 chars.

Example: if i manually write "Hello" on the field and run:

$('#presentation')[0].validity.valid
/*will return "false" as expected*/

but if i use any of this way to change the value of the field:

 $('#presentation').prop('value','hell')
//or
 $('#presentation').val('hell')
//or
 $('#presentation')[0].value='hello'

It will cause:

$('#presentation')[0].validity.valid
/*will return "true" and will cause a validation problem*/

it set the field to valid, and the only way to revalidate is to change the value in the field, manually. this will cause that invalid data could be submitted in the form this field will not be checked.

This is happening in Chrome, firefox, edge and opera.

do you know if there's anyway to force the field to validate his value?

here a fiddler with this problem: https://jsfiddle.net/rfigueiredo/jnuhfsc7/20/

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