Skip to content

How to make a checkbox option disabled once only a single checkbox is checked? #6407

Answered by Hiws
jithinb68 asked this question in Q&A
Discussion options

You must be logged in to vote

You can bind a method to disabled, which checks whether the checkbox should be disabled or not. In your case you want to check if there's only one item in the selected array, and disable the checkbox which value is in the array.

<div id="app" class="p-2">
  <b-form-checkbox-group v-model="selectedFruit">
    <b-form-checkbox v-for="fruit in availableFruits" :key="fruit.id" :value="fruit.name" :disabled="isDisabled(fruit)">
      {{ fruit.name }}
    </b-form-checkbox>
  </b-form-checkbox-group>
</div>

<script>
new Vue({
  el: '#app',
  data() {
    return {
      selectedFruit: [],
      availableFruits: [{
          id: 1,
          name: 'Banana'
        },
        {
          id: 2,

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Hiws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #6406 on February 03, 2021 14:33.