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

I must interact with the video within the iframe by clicking on it

I am trying to interact with an iframe video on a webpage. Here is the code snippet for the video: <div class="videoWrapper" style="" xpath="1"> <iframe width="854" height="480" src="xxxxxxx" frameborder="0" allow="autoplay; encrypted-media" all ...

Executing an AngularJS function using regular JavaScript code

I am currently working with AngularJS and Typescript. I have integrated an external library into my project and now I need to call an AngularJS method from that library, which is written in vanilla JavaScript. I tried following this example, but unfortunat ...

Using a Typescript variable prior to its assignment

I encountered an issue in my Typescript / ReactJS project displaying the error message Variable 'myVar' is used before being assigned. TS2454 This problem arises with my TS version 4.2.3, appearing both in my IDE and during code execution. Inte ...

Unable to process the post request

I've encountered an issue while attempting to redirect using the res.redirect() function. When I submit the form, it should insert the data into the database and then redirect me to the home root. However, instead of successfully redirecting, I'm ...

Having trouble triggering a method on button click using Vuetify's v-btn component

I am facing an issue with executing a method when clicking on a v-btn. Here is my template <template> <v-app> <v-main> <v-card class="mx-auto" max-width="500" tile> <v-text-field ...

Update the content of a div on the WordPress homepage with the click of a button

Hey there, I'm currently working on customizing the Boutique theme for a website. My goal is to add two buttons to the home page that will display different sets of products when clicked. I've been attempting to use the visibility property, but h ...

Using NodeJS to integrate WebRTC into JavaScript applications

I am facing a challenge with my JavaScript files that I need to use for creating a WebRTC application. Unfortunately, my hosting platform does not support Node.js. I'm wondering if it's possible to modify these JS files to work without Node.js. C ...

Ways to modify the screen when a click event occurs

To make the display block when clicking this icon: <div class="index-navi-frame-box"> <p onclick="expandFunction()"> <i class="fa fa-bars"></i> </p> </div> Here is what it should change to: <div class=" ...

How can I utilize the Json data retrieved through the findById method in my code?

My current project involves creating an API that retrieves data from Patients (id and name), Physicians (id and name), and Appointments (id, phyId, patId, app_date) in order to display the patients scheduled to see a specific physician. To achieve this, I ...

Is it possible for me to avoid html tags inside a class without using the xmp tag?

There are a few ways to approach this question. It's important to decide which method will be most beneficial for your specific needs... Is it possible for JavaScript to recreate the deprecated <xmp> tag using an "xmp" class? Can we replicate Sta ...

Unable to trigger AJAX POST with jQuery click handler

Important Note: Personally, I have a preference for utilizing jQuery over the shorthand $; although it involves more typing, I find it to be more readable. I am working on a simple form that allows users to input their first and last names as well as an e ...

Issues with jQuery .click and .html functions not functioning as expected

Does anyone have experience creating a game with jQuery? I can't seem to get the options after the first choice to work. Sorry, I don't have a working example at the moment. --- jQuery --- $(document).ready(function() { $(".console"). ...

What is the best way to extract the src attribute from an image tag nested within innerHtml?

In the developer tools, navigate to console and enter: var x= document.getElementsByClassName('ad-area')[0].innerHTML; x returns: '<a href="/members/spotlight/311"><img class="block-banner" src="https://tes ...

Observable Knockout Dependency

I found an interesting example on the KnockoutJS site () and I want to implement something similar. My goal is to check if certain values are available on the client side when a category is selected. If they are not, then I need to fetch them from the ser ...

Is there a way to deliver information to a specific element on a client's HTML page?

My current project involves using Node.js to serve a webpage that collects user inputs and stores them in a mongodb server. The web page also displays these user inputs. I am trying to determine the best way to pass the user inputs from node.js to the < ...

Capture JavaScript results using PHP

I'm looking for a way to save the output or result of JavaScript code. For example: <script>document.write(navigator.appVersion)</script> When it comes to PHP, I have no issues: $ip = $_SERVER['REMOTE_ADDR']; $file = "log.txt ...

Showing real-time information from an object

I am attempting to showcase the 'helpText' data on the front end based on the type. Is it feasible to include a conditional statement (metricsType variable) and the [key] value into what I want to return? The final 'p' below provides an ...

What is the best way to update a specific element within a web page?

My current implementation involves utilizing this code snippet within a functional component : return ( <div style={{ height: "700px", overflow: "auto" }}> <InfiniteScroll pageStart={0} loadMore={Fet ...

Showing fixed values inside directive view after successful injection

Looking for some answers about using constants in angularjs. Here are the constants defined in my app.js: ... angular .module('blocTime', ['firebase', 'ui.router']) .config(config) .constant(&apos ...

Utilize highlight.js in a Vue application to dynamically emphasize a block of text

In my VueJS project, I have developed a component for displaying content from a WYSIWYG editor (tiptap). The backend is returning the following content: let x = 0; enum A {} function Baa() {} To highlight this code snippet, I am using highlight.js in th ...