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

165
Views
How to handle multiple validations on submit (Vue.js)

Hi there, I need to validate several inputs before letting the user submit:

  <button type="submit" v-on:click="validateErrors()" @click.prevent="submit">Finalizar</button>

I did a method validateErrors in order to handle all of the validations separately:

   validateErrors() {
     if (this.campaign.selectedBox == null) {
      this.$set(this.msg, 'selectedbox', 'Alert 1') ;
      return true;
     }
     if (this.campaign.selectedExtras == null) {
      this.$set(this.msg, 'selectedextras', 'Alert 2') ;
      return true;
     }
   },

Lastly, I made an alert with the different messages to show in case one (or various) of the inputs don't validate:

<div class="alert alert-info w-100" v-if="msg.selectedbox">{{msg.selectedbox}}</div>
<div class="alert alert-info w-100" v-if="msg.selectedextras">{{msg.selectedextras}}</div>

Only the first of the validations is working, how can I handle multiple validations with their own alerts being executed by the same function on submit?

Thanks a lot!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Instead of creating this function you can add rules for the input and then use form validator in vuejs https://v2.vuejs.org/v2/cookbook/form-validation.html But if you want to stay using this function you can do this

function validateErrors() {
  var check1 = false;
  var check2 = false;
  if (this.campaign.selectedBox == null) {
    this.$set(this.msg, "selectedbox", "Alert 1");
    check1 = true;
  }
  if (this.campaign.selectedExtras == null) {
    this.$set(this.msg, "selectedextras", "Alert 2");
    check2 = true;
  }
  return {check1:check1, check2:check2};
}
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!