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