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

169
Visualizações
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 Respostas
Responde à pergunta

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 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