Exploring the functionality of v-chips within a v-text-field

I am trying to implement a search text field using vuetify's v-text-field, and I want to display the user input in a chip (such as v-chip or v-combo-box). However, v-text-field does not seem to support chips based on the documentation. Is there a workaround for this problem? I attempted to use v-combo-box, but it only works when Enter is pressed, and I cannot retrieve the search value from v-model when clicking on the icon within v-combo-box.

<template>
  <div>
    <!-- <v-combobox v-model="search" chips clearable @keyup.enter="onEnter">
      <v-icon small @click.stop="submit"> fas fa-search </v-icon>
    </v-combobox> -->
    <v-text-field chip v-model="search" label="Search" hint="Company and Campaign Name" clearable autofocus append="hey" @keyup.enter="onEnter">
      <v-icon slot="append" small @click="submit"> fas fa-search </v-icon>
    </v-text-field>
  </div>
</template>

<script>
import Vue from 'vue'

export default Vue.extend({
  name: 'MultiSearch',
  data() {
    return {
      search: '',
    }
  },
  methods: {
    submit(event) {
      event.preventDefault()
      console.log('this search', this.search, event)
      this.$emit('updateSearch', this.search)
    },
    onEnter(event) {
      console.log('this search', this.search)
      this.$emit('updateSearch', this.search)
    },
  },
})
</script>

<style lang="stylus" scoped>
.v-text-field >>> .v-label
    color:black !important
    caret-color: black !important

.v-text-field >>> .v-input__control
        color:black !important
        caret-color:black !important

@media only screen and (min-width:320px) and (max-width:480px){
  .v-text-field{
      width:200px;
  }
}

.v-text-field{

}
</style>

Answer №1

@curiosityrock, You can display a chip inside the text field

Check out the code snippet below:

<div id="app">
  <v-app id="inspire">
    <v-form>
      <v-container>
        <v-row>
          <v-col
            cols="12"
            sm="6"
            md="3"
          >
            <v-text-field
              label="Regular"
              v-model="textBox"
            >
              <template v-slot:append> 
                <v-btn icon @click="addChips"><v-icon>mdi-magnify</v-icon></v-btn></template>
              <template v-slot:prepend-inner>
                <div v-for="(chipText , index) in chipData" :key="index">
                  <v-chip class="ma-1">{{chipText}}</v-chip></div>
              </template>
            </v-text-field>
          </v-col>
        </v-row>
      </v-container>
    </v-form>
  </v-app>
</div>

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  data() {
      return {
        chipData: [],
        textBox: "",
      }
  },
  methods: {
    addChips() {
      if (this.textBox.length) {
        this.chipData.push(this.textBox)
        this.textBox = ""
      }
    }
  }
})

You can view the working example on CodePen here: https://codepen.io/chansv/pen/wvggwWj?editors=101

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

Protecting your CakePHP 3 application with the Security component and enhancing form fields with VueJS

Currently, I am developing a software application that utilizes Vue.js and CakePHP 3.6. Whenever I try to submit data using the POST method, the security component triggers a 400 error due to missing _Token fields. While CSRF token implementation is worki ...

DIV size issue resolved

Content within a div is surpassing the set fixed size determined by CSS. <style> #fixeddiv { position: fixed; margin: auto; max-height: 300px; max-width: 700px; } </style> <div id="fixeddiv"> <div id="M77 ...

What is the best way to utilize proxyTable for handling cross-origin requests within a vue-cli project?

I'm having trouble setting up a proxyTable with axios in my vue-cli project. In the configuration file config/index.js, I added the following code: proxyTable: { '/getnews': { target: 'https://xx.xxx.xx.x' changeOrigin: ...

How can I use HTML code to style the header cell values of a table?

Can someone please assist me with creating a table header style that looks like the one in the image? Additionally, how can I turn the name and picture area into a block and add borders to them? I'm also having trouble with my list icons showing up a ...

Animating CSS using JavaScript

Recently diving into the world of JavaScript, I've taken on the challenge of creating an analog clock. I began by crafting the second hand using CSS but now I'm eager to transition it to Javascript without relying on jQuery or any other JS framew ...

Place the first paragraph within a div above another paragraph in the same div

Presently, I have this item: https://i.stack.imgur.com/0dBd9.png however, my objective is to achieve this look: https://i.stack.imgur.com/NEBZf.png The code snippet in question is as follows: .bonus-div { width: 290px; height: 29px; ma ...

What is the Vue.js equivalent of Angular's ng-container?

When working with Angular, you may come across a tag called ng-container which is used in the following way: <ng-container *ngIf="false">this won't be shown</ng-container> According to the Angular documentation: The Angular is a grou ...

Styling Dynamic HTML Content in Angular: Tips and Tricks

After running this line of code, I have a generated element sub with a property of [sub]. <li [displayMode]="displayMode" template-menu-item style="cursor: pointer" [routerLink]="['/request/checkoutReview']" icon="fa-shopping-cart" name ...

The element was rendered numerous times

I have implemented a conditional rendering logic using a v-if-statement as shown below: <div v-if="resp > 1023"> <PdfViewer /> </div> <div v-else> <PdfViewer /> </div> The issue I am facing is that ...

Creating a horizontal layout for list items that are responsive using CSS

My website has a "Featured" section with 3 equally sized elements displayed horizontally. I want to make the webpage responsive by using percentage widths, but when I resize the window to less than the list width, the items stack on top of each other. Che ...

Navigating to a specific tab within the Bootstrap-vue tabs while using vue routes

I have implemented tabs using Bootstrap-vue in my project. The HTML code for the tabs is as follows: <b-tabs> <b-tab title="Exotic Dogs" href="#dogs"> <br>Content for Dogs tab here </b-tab> <b-tab title="Exotic Cats" h ...

Modify the state of each individual button

I recently came across a cool implementation using clicks and jQuery fade effects to show a div when a button is clicked and then change the state of the button. Check it out here: http://jsfiddle.net/ttj9J/5/ HTML <a class="link" href="#" data-rel="c ...

Ensuring the accuracy of a single field within a form containing multiple fields is made possible through the utilization of

I am facing an issue with my emailValidation method. Even though I want it to run when this.$refs.editUserForm.validate('email') returns true, it always seems to return false, especially when a valid email like <a href="/cdn-cgi/l/email-protec ...

I'm having trouble displaying the result of my calculation in the code. Could it be because I forgot to include an output tag?

I am attempting to develop a Miles Per Gallon (MPG) calculator using Javascript. However, I'm encountering difficulties with displaying the results once the "Calculate" button is pressed. <html> <head> <title> MPG Calculator </ti ...

Tips for adding animation effects to elements when transitioning to a new page using Vuetify

Is there a way to animate the initial display of a page when navigating to it? Here is the code I am currently working with: https://jsfiddle.net/uLhzqxg9/68/ This is the HTML portion: <div id="app"> <v-app dark> <div class ...

Encountering Issues with Formatting InnerHtml Text using RegEx

Technology: React.js I have been working on a custom function in JavaScript to highlight specific words within a code block. The function seems to be functioning correctly, but the highlighting isn't staying after the function is completed. Any ideas ...

I just obtained the height measurement of a dynamic table - now I must transfer this height value to a different element

Recently, I encountered a situation where I needed to get the height of a dynamic table using code like this: var table = document.getElementById("test"); document.write(table.offsetHeight); However, the challenge arose when I realized that I also needed ...

Setting character limits within textareas based on CSS classes in a dynamic manner

I'm looking to develop a JavaScript function that can set text limits for multiple textareas at once using a class, allowing for flexibility in case specific textareas need to be exempt. However, I'm facing issues with my debuggers - Visual Studi ...

The footer should never be positioned below the sidebar

Hello, I'm trying to position my footer below my side navigation bar. It's working fine with the header, but I can't seem to figure out how to do it for the footer. Also, another question - how can I ensure that the text on a smaller screen ...

Tips for invoking a specific function based on a value within a v-on callback

Here's my code snippet: <form @submit.prevent="buttonName === 'Create' ? createCountries : updateCountries"> ----- ---- </form> methods :{ createCountries(){ ---- }, updateCountries ...