Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda