0
votes

I read the docs yet I can't find any example of a bootstrap vue checkbox being set to check/unchecked when clicking a table row (when it is underneath a table). Is there a way that clicking a row will result to it being checked/unchecked?

data() {
  return {
    form: {
      optional: {} as { [index: string]: boolean },
    }, 
  };
},
methods: {
  triggerCheckBox(relatedId: string) {
    const val = this.form.optional[relatedId];
    this.form.optional[relatedId] = !val;
  },
}

<tr v-for="related in liability.related" @click="triggerCheckBox(related.id)">
  <td>
    <b-form-checkbox
      v-model="form.optional[related.id]"
    </b-form-checkbox>
  </td>

Edit: I already manipulated the v-model bind to the checkbox. Still doesn't work.

2
Typically, you'd just toggle the value that the checkbox is bound to (its v-model). What does your code look like?Phil
Edited. I just didn't post the code because I assumed this is the default behavior of the checkbox on bootstrap vue where the changes on the model isn't 2 way binding which was confirmed on my code. I also notice that setting the default values to true doesn't set the checkbox to checked.The Bassman
Adding new properties to your objects defined in data() (ie this.form.optional[relatedId] = !val) is not reactive. See vuejs.org/v2/guide/reactivity.html#Change-Detection-CaveatsPhil

2 Answers

2
votes

I added this on my code on my created hook:

this.$set(this.form.optional, related.id, false));

to set the form.optional to reactive..

0
votes

just make sure you put the prop

value=true unchecked-value=false
v-model="varaible_of_your"
***"variable_of_your=true or false"