Home > Mobile >  Vue- How can I control the behavior of chips in v-autocomplete?
Vue- How can I control the behavior of chips in v-autocomplete?

Time:11-12

I have a 20-25 names coming from API where I'll need to show them in a drop down box (requirement). I'm using Vue v-autocomplete here to display the selected names on the field. I've used custom item called Select All where the user can select all the names in the drop down list, but what I also need to do when the user clicks on Select All is that I don't want to show all the names in the Autocomplete field including Select All Chip. Only items that are selected individually without Select All should show as Chips.

Here is my code sandbox I've attempted so far. I'm new to Vue js, so I'm hoping to get some thoughts on controlling the chips on v-autocomplete.

v-autocomplete sandbox

CodePudding user response:

Instead of including "Select All" in the array of names, you can use the prepend-item slot to include a separate Select All checkbox.

If you need to differentiate between names selected via individual click and those selected via the Select All checkbox you will probably need a new property in the names array to track that, say a boolean that is true if selected one way and false the other.

You'll also need a slot like selection to customize the display of your chips where you can use v-if to conditionally render a chip based on that new boolean property.

This codesandbox I believe is pretty close to what you're after

  • Related