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

180
Vistas
Set Function as Compare in Form Validation using Declarative plugin

We are using FormValidation.io for form validations, now we are trying to use the identical validator using the html attributes which is applied via the Declarative plugin.

What we want? We want the validation to check that confirm field is same as password field if not it should fail validation

<input
  class="form-control"
  data-fv-not-empty="true"
  data-fv-not-empty___message="The password is required" 
  type="password"
  placeholder="Password"
  name="password"
  id="input-password"
  autocomplete="off"
>
     
<input 
  class="form-control" 
  data-fv-identical="true" 
  data-fv-identical___compare="getPassword()" 
  data-fv-identical___message="The password and its confirm are not the same" 
  type="password" 
  placeholder="Confirm Password" 
  name="confirm" 
  id="input-confirm" 
  autocomplete="off"
>
     
<script>
function getPassword() {
  return $('#input-password').val();
}
</script>

Now the document states we can declare the compare value as both a string or a function that returns string. Now even if we call a function there it still converts the value as string so as per our current code will show the confirm to be invalid until the value of confirm is not equal to "getPassword()" not the output of this function but this exact string.

We would like to know how can we set compare using html attributes. We can achieve the same using the programatic way but we want to make it work using Declarative mode

Documentation links

https://formvalidation.io/guide/validators/identical/ https://formvalidation.io/guide/plugins/declarative/ https://formvalidation.io/updates/

Thanks in advance.

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

0

I directly got in touch with the original developer of FormValidation and he stated that this is something we cannot achieve using html attributes.

Chat with the founder

So we wont be able to achieve this without modifying the core plugin itself.

Hope this helps anyone who was looking for the same answer.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I just run into this problem. As a workaround I use this trick:

var fv = form.fv;

fv.updateValidatorOption(input.name, 'identical', 'compare', function(){
  return inputConfirm.value;
});

Of course in a entry point where I init validation for all forms in a loop I save instance in form prop: form.fv = fv;

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