jeudi 3 octobre 2019

VueJs 2 - Force Checkbox DOM value to respect data value

I cannot for the life of me figure this out.

I want

  1. User clicks checkbox
  2. Then based on separate conditions
  3. Checkbox data value & rendered value are calculated separately and return checked / unchecked

I can get:

  1. The data value to calculate and interpolate properly

But I fail at:

  1. If a false checkbox is clicked and the data calculation returns false, the checkbox still toggles onscreen to checked and unchecked

I’ve tried:

  1. Using a v-model with a custom setter that does the calculation and sets the local state which the custom get returns
  2. Imitating a v-model using @change.prevent.stop="updateCalculatedValue" and :checked="calculatedValue"
  3. Assuming the @change happens after the @click (which i think is wrong) and using @click.prevent.stop="updateCalculatedValue" and :checked="calculatedValue"

The model is working and rendering the calculated value as string in a DOM span, but the checked value doesn't seem to respect the model value

Can someone please help me out?




Aucun commentaire:

Enregistrer un commentaire