0

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.

3
  • 1
    Typically, you'd just toggle the value that the checkbox is bound to (its v-model). What does your code look like? Commented Oct 16, 2018 at 2:46
  • 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. Commented Oct 16, 2018 at 2:53
  • 1
    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-Caveats Commented Oct 16, 2018 at 2:54

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

just make sure you put the prop

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.