I have a table, each row has a checkbox, name, another checkbox, and dropdown. I want to have the dropdown disabled by default, and only enable it when check the first checkbox.
Here's the HTML:
<tbody>
<tr v-for="item in Items" v-bind:id="item.ID">
<td>
<!-- check this checkbox and enable/disable the dropdown -->
<input type="checkbox" v-on:click="onSelect($event)" v-model="item.Selected" />
</td>
<td>
{{ item.Name }}
</td>
<td>
<input type="checkbox" v-model="item.isActive" /><
<td>
<!-- enabled/disabled depending on if checkbox is checked -->
<select v-bind:disabled="">
<option value="foo">foo</option>
<option value="bar">bar</option>
</select>
</td>
</tr>
</tbody>
Currently, the onSelect($event) method will check the second checkbox in the same row when checked.
Here's my JavaScript:
var vm = new Vue({
el: '#app',
data: {
items: items
},
methods: {
onSelect: function (event, id) {
setTimeout(function () {
var idx = $(event.target).closest('tr').index();
if (items[idx].Selected) {
items[idx].isActive = true;
}
}, 100);
}
}
});
Is there a way to bind the enabling/disabling of the dropdown to a checkbox with VueJS 2/JavaScript/jQuery?