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

230
Visualizações
How to use HTML5 validation check for inputs in Vuejs

How to use html5 form.checkValidity() with form of custom components in vuejs 2?

With html5 inputs, form validation works well:

<form name="myform" ref="formref">
  <input type="text" required /> 
  <button type="submit" @click="submitForm">Ok</button>
</form>
...
methods: {
  submitForm() {
    if (this.$refs.formref.checkValidity()) sendData();
    else showError();
  }
}

But if I use custom components, that won't work:

<form name="myform" ref="formref">
  <MyCustomInputComponent :required="true" /> 
  <button type="submit" @click="submitForm">Ok</button>
</form>

checkValidity() of the form will always return true.

The question, is how should I implement MyCustomInputComponent to let it works with HTML5 forms validation?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I see two options:

  1. Trying to validate the custom field inside the component. For this I would use @keyup event to fire the validation before submition. If you are using vuetify (it is a very common library) you can use the rules tag to do it.

  2. Use an external library called veeValidate for this.

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