When text with delimiters is pasted into a Vuetify combobox, why aren't the chips separated correctly by the delimiters?

I'm attempting to create a Vuetify combobox with chips that automatically split the input based on predefined delimiters, such as ,. This means that if I paste the text a,b,c, the component should convert them into three separate chips: a, b, and c. However, it is not working as expected.

<template>
  <v-container>
    <v-row>
      <v-col>
        <v-combobox
          v-model="chips"
          chips
          :delimiters="[',']"
          append-icon=""
          clearable
          hint="Hey I'm a 🥔 hint!"
          persistent-hint
          label="Type your favorite 🥔s"
          multiple
          solo
          @update:search-input="meowInput"
        >
          <template v-slot:selection="{ attrs, item }">
            <v-chip
              v-bind="attrs"
              close
              :color="getColor(item)"
              @click:close="remove(item)"
            >
              <strong>🥔{{ item }}</strong
              >&nbsp;
            </v-chip>
          </template>
        </v-combobox>
      </v-col>
    </v-row>
  </v-container>
</template>

<script>
import ColorHash from "color-hash";

export default {
  name: "Experimental",
  components: {},
  data() {
    return {
      select: [],
      chips: [],
      search: "", //sync search
    };
  },
  methods: {
    meowInput(e) {
      console.log(e);
    },
    getColor(item) {
      const colorHash = new ColorHash({ lightness: 0.9 });
      return colorHash.hex(item);
    },
    remove(item) {
      this.chips.splice(this.chips.indexOf(item), 1);
      this.chips = [...this.chips];
    },
  },
};
</script>

Any suggestions on how I can achieve this desired behavior?

Answer â„–1

To keep track of changes in the search-input, you can bind and synchronize it with other elements by splitting the search value and appending it to the chips.

search-input: Refers to the search value that can be synced using the .sync modifier.

<v-combobox
  // ...
  :search-input.sync="search"
  // ...
>

// ... 

updateChips(input) {
  if (this.search && this.search.split(",").length > 1) {
    this.chips = this.chips.concat(
      this.search.split(",").filter((term) => !this.chips.includes(term))
    );
    this.search = "";
  }
}

Demo Link

Click here for a demo!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Identify compatibility with the background-attachment property set to fixed

I've been searching for an updated answer on this topic, but I couldn't find one so I wanted to confirm. My goal is to achieve a parallax effect using background-attachment: fixed, however I've noticed that it doesn't work on mobile ph ...

Creating a dynamic multi-choice dropdown list with Django and Vue.js

I have been attempting to implement the Vue.js multiselect component from the following link: However, I am encountering an issue where instead of the expected multiselect dropdown, the output is not as desired and looks like this: https://i.sstatic.net/ ...

When there is no content in the responseText, AJAX will display an error

I've encountered an issue while trying to fetch data using AJAX. The problem lies in receiving an empty responseText. Here's the code I'm working with: JavaScript: function getFounder(id) { var founder = ""; $.ajax({ ...

What is the best way to toggle the active class on a ul list?

After clicking, the active class remains on the original "li" instead of changing as it should. I've tried modifying the code but haven't been able to find a solution. Can someone please review what I might have missed? It seems like there's ...

Dynamic data retrieval with the power of JavaScript and AJAX

When attempting to send data using AJAX in PHP, I encountered an issue with my jQuery click function on a button that sends data only when the quantity is greater than 1. The error arises because PHP does not recognize the variables 'name' and &a ...

Challenge with JavaScript personalized library

No matter how many times I review my code, I find myself perplexed. Despite my efforts to create a custom library of functions from scratch (shoutout to stackoverflow for guiding me on that), the results are leaving me puzzled. A javascript file is suppose ...

Using Javascript to save content to a text file across multiple lines

I am working on a coding project that involves extracting data from a JSON file via a URL and parsing the JSON content. The script successfully filters out the necessary data, but now I want to write this data to a text file with each piece of information ...

Retrieving raw PCM data from webAudio / mozAudio APIs

I have been exploring ways to store the output from the webAudio API for future reference. It seems that capturing PCM data and saving it as a file might meet my needs. I am curious to know if the webAudio or mozAudio APIs have built-in functionality for ...

How can I retrieve information from an HTML or JavaScript object?

Imagine a scenario where you have an HTML table consisting of 5,000 rows and 50 columns, all generated from a JavaScript object. Now, suppose you want to send 50 checked rows (checkbox) from the client to the server using HTTP in JSON format. The question ...

Connecting a controller to a directive in AngularJS: A step-by-step guide

Imagine a scenario with the following HTML structure: <div ng-app="testApp"> <div ng-controller="controller1"> {{controller1}} </div> <div ng-controller="controller2"> {{controller2}} </div> ...

Serializing Form Data with Checkbox Array

I am currently utilizing JQuery to submit a form using the form.serialize method. However, within the same form, there is an array of checkboxes that are dynamically created by a PHP function. Here is the structure of the form: <form class="form" id="f ...

What is the method for accessing 'this' beyond the scope of my object?

My Jcrop initialization for a website includes my own namespace. I have a question regarding the this keyword. Whenever I need to access my base object called "aps" in any callback function, I have to wrap this in a variable (I chose the word that). Is t ...

Incorporating React's dynamic DIV layout algorithm to generate a nested box view design

My goal is to showcase a data model representation on a webpage, depicting objects, attributes, and child objects in a parent-child hierarchy. I had the idea of developing a versatile React component that can store a single data object while also allowing ...

Steps to create a submit button that is linked to a URL and includes an image

I'm attempting to convert my submit button into an image that, when clicked, redirects to another page. Currently, the submit button is functional but lacks the desired image and href functionality. <input type="submit" name="submit" alt="add" o ...

Utilizing AJAX to showcase an HTML popup

I am currently working on a project to create an HTML page that will display another HTML file in an alert when a button is pressed. However, I am facing an issue where the content is not being displayed as expected. <html> <head> ...

Automatically updating client-side values in AngularJS using setInterval()

Implementing a value calculator on the client side using AngularJS. I need to update the main value of the calculator every 5 minutes with setInterval(). This is my AngularJS code: $http({method: 'GET', url: '../assets/sources.json'} ...

When running a Docker container, the npm module may not be found

I'm encountering an issue while trying to run my Vue application with Docker. Upon updating npm packages locally, I encounter the following error: - Building for production... ERROR Failed to compile with 1 error8:17:57 AM This relative module was n ...

What is the best way to import the L module from the "leaflet" library in Next.js?

Implementing Leaflet into my Next.js development posed a challenge as it did not support server side rendering (SSR). To address this, I had to import the library with SSR disabled using the following approach: import React, {Component} from "react&qu ...

Is there a way to switch tabs through programming?

Is there a way to switch between tabs using jQuery or JavaScript when using the tabbed content from ? I have tried using $("tab1").click(); I have created a fiddle for this specific issue which can be found at: https://jsfiddle.net/6e3y9663/1/ ...

Tips on creating a script for detecting changes in the table element's rows and columns with the specified data values

I have a div-based drop-down with its value stored in TD[data-value]. I am looking to write a script that will trigger when the TD data-value changes. Here is the format of the TD: <td data-value="some-id"> <div class="dropdown">some elements& ...