Prevent specific chips from being removed from combobox
P粉674757114
P粉674757114 2024-02-03 16:42:39
0
1
362

I have these combobox chips but there is a problem deletable-chips

<v-combobox
    v-model="selectedCategories"
    :items="attributeCategories"
    item-text="name"
    item-value="id"
    label="Category"
    multiple
    chips
    clear-icon="mdi-close-circle"
    deletable-chips
    v-on:change="changeCategory(selectedCategories)"
></v-combobox>

Is there a way to prevent specific chips from being deleted? For example, not showing a delete button on a specific button? Assume that for Device and only Weather and Geo Location

are allowed to be deleted
P粉674757114
P粉674757114

reply all(1)
P粉354948724

Instead of using the v-chips built-in deletion method. You can do this by customizing the @click:close event. I created a working demo for you:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data: () => ({
    model: [],
    items: [
      {
        text: 'Weather'
      },
      {
        text: 'Geo Location'
      },
      {
        text: 'Device'
      }
    ]
  }),
  methods: {
    remove (itemText) {
      if (itemText === 'Device') {
        return;
      } else {
        this.model.forEach(obj => {
          if (obj.text === itemText) {
            this.model.splice(this.model.indexOf(obj), 1)
          }
        })
        this.model = [...this.model]
      }
    }
  }
})
sssccc
sssccc


Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!