0

I have a code here:

<b-form-input v-model="search" placeholder="Search"></b-form-input>
<b-form-checkbox-group v-model="selected" :options="options" stacked></b-form-checkbox-group>
search: null,
selected: [],
options: [
  {
    value: 'apple',
    text: 'Apple'
  },
  {
    value: 'orange',
    text: 'Orange'
  },
  {
    value: 'grape',
    text: 'Grape'
  }
],

I want to create a simple search regarding the code above.

From this: enter image description here

To this: enter image description here

I am using https://bootstrap-vue.org/docs/components/form-checkbox

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Commented May 30, 2023 at 5:15

1 Answer 1

0

You can use a computed property with a javascript array filter for that. Like:

export default {
  data() {
    return {
      search: '',
      options: [
        {
          value: 'apple',
          text: 'Apple',
        },
        {
          value: 'orange',
          text: 'Orange',
        },
        {
          value: 'grape',
          text: 'Grape',
        },
      ],
    }
  },
  computed: {
    filteredOptions() {
      return this.options.filter((option) =>
        option.value.includes(this.search.toLowerCase())
      )
    },
  },
}

You can find a working example here, without using your bootstrap component.

Replace the options by filteredOptions and that probably should work:

<b-form-checkbox-group v-model="selected" :options="filteredOptions" stacked></b-form-checkbox-group>
Sign up to request clarification or add additional context in comments.

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.