Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!