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

166
Views
How to active Switch when dynamic form input changes in Vue js

Well, this question came after this question of mine. How to disable button if multiple form inputs do not change in Vue.js

There is Switch at every form. When a form inputs are changed, the switch needs to be ON from the OFF state. I have done it by putting this line into the watch method on each form

this.items.forEach( (_, index) => {
  this.$watch(['items', index].join('.'), {deep: true, handler: (newVal, oldVal) => {
      this.changed.push(newVal.id)
      this.items[index].switch = true
     }});
  });

After adding this line, this.items[index].switch = true, the Switch is getting ON from OFF; but if a user then OFF the Switch again by clicking on the Switch; the text is not changing anymore. It's always remaining ON. how to fix that?

CodePen Demo

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

0

If you add this line to watch every time you change this model the switch is set to true. You need a conditional, try this.

this.items[index].switch = this.changed.includes(newOld.id)
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!