vue-js-toggle-button icon indicating copy to clipboard operation
vue-js-toggle-button copied to clipboard

Sync doesn't work as expected, value/v-model can get out of sync

Open aldencolerain opened this issue 7 years ago • 5 comments
trafficstars

If I have the toggle in sync mode connected to a value using v-model (or :value and @input) the toggle can get out of sync of the value.

When sync is selected the toggle function could not set this.toggled = !this.toggled directly, but could just send the value through the input event and let the parent's v-model handler set the value.or quickly changes.

aldencolerain avatar Aug 27 '18 01:08 aldencolerain

Maybe something like...

toggle (event) {
  if (!this.sync) {
    this.toggled = !this.toggled;
  }
  this.$emit('input', this.toggled);
  this.$emit('change', {
    value: this.toggled,
    srcEvent: event
  });
}

aldencolerain avatar Aug 27 '18 02:08 aldencolerain

Is there any way to get around this issue in the current version?

pineapplegum avatar Oct 11 '18 12:10 pineapplegum

@stanleyck Try to remove v-model and leave only value and set sync = true. Then, there is exist change event that you can use to change the field of your model avoiding v-model

YuryKorovko avatar Dec 04 '18 14:12 YuryKorovko

Just saw @aldencolerain 's comment right now - made a PR - happy to add you to it :)

veebuv avatar Mar 27 '19 01:03 veebuv

is there any update on this?

soknifedev avatar Sep 12 '21 20:09 soknifedev