Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda