Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Manipulating checkboxes that were created from v-for

this is my first time posting, so sorry for any inconvenience.

I am having problems with vue-js, that is with its component manipulation.
I am creating some checkboxes from an array, which have a String called property and a boolean called checked.

Here is my array:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

checkedRequests: [
    {
      property: 'cid',
      checked: true
    },
    {
      property: 'companyName',
      checked: true
    },
    {
      property: 'gln',
      checked: true
    },
    {
      property: 'address',
      checked: true
    },
]

And here is my vue div:

<div class="checkDiv" v-for="item in checkedRequests" :key="item.property">
  <input type="checkbox" id="item.property" v-model="item.checked">
  <label for="item.property">{{ item.property }}</label>
  <br>
</div>

My Problem is that when i try to check or uncheck any boxes, only my first property is getting manipulated, e.g ‘cid’. In other words: If I click on address for example to toggle checked to false, ‘cid’ instead will toggle. The data is being portayed correctly but since the Array is false the checked boxes are alwas incorrect.

Thanks in advance!

>Solution :

Right now you have id="item.property" and for="item.property" as a string, using a binding :id="item.property" and :for="item.property" should solve your problem

  <div class="checkDiv" v-for="item in checkedRequests" :key="item.property">
    <input type="checkbox" :id="item.property" v-model="item.checked" />
    <label :for="item.property">{{ item.property }}</label>
    <br />
  </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading