How to capture the "chip close" event in Vuetify

Exploring the vuetify realm as a newcomer, I find myself grappling with event handling while working on my first web app project. Specifically, I am currently developing a "UserPicker" component using VAutocomplete.

This component functions by sending an asynchronous request to a server that responds with a list of user accounts matching the input provided by the user.

The desired outcome should resemble the example demonstrated here: https://vuetifyjs.com/en/components/autocompletes/#slots

Everything seems to be functioning correctly, except for my difficulty in capturing events related to this specific issue.

Below is the code I have crafted:

<script setup lang="ts">
import { ref, watch } from "vue";
import { useServerRequestsStore } from "@/stores/server-requests";
const input = ref();
const items = ref<Array<UserPreview>>([]);
const select = ref<Array<UserPreview>>([]);
const selectSet = new Set();
const search = ref("");
const serverRequests = useServerRequestsStore();

interface UserPreview {
  firstName: string;
  lastName: string;
  username: string;
  avatar: string;
}

function addUser(userItem: UserPreview) {
  try {
    selectSet.add(userItem.username);
    select.value.push(userItem);
    items.value = [];
    search.value = "";
    input.value.focus();
  } catch (error) {
    console.log(error);
  }
}
function removeUser(userItem: UserPreview) {
  selectSet.delete(userItem.username);
  const toRemove = select.value.findIndex(
    (added) => added.username == userItem.username
  );
  console.log("removing " + userItem.username + " at index " + toRemove);
  select.value.splice(toRemove, 1);
  console.log("after removal:", select.value);
}

watch(search, async (val) => {
  if (val.length == 0) return;
  try {
    const users = await serverRequests.getUserByUsername(val, false);
    items.value = users
      .filter((user: any) => !selectSet.has(user.userInfo.username))
      .map((user: any) => ({
        firstName: user.userInfo.firstName,
        lastName: user.userInfo.lastName,
        username: user.userInfo.username,
        title: user.userInfo.username, //richiesto per far comparire automaticamente i suggerimenti
        avatar: user.userInfo.profilePicture,
      }));
  } catch (error) {
    items.value = [];
  }
});
</script>
<template>
  <VAutocomplete
    @keydown.enter.prevent
    ref="input"
    v-model="select"
    v-model:search="search"
    :items="items"
    class="mx-4"
    density="compact"
    hide-no-data
    hide-details
    label="Seleziona destinatari"
    style="max-width: 300px"
    chips
    closable-chips
    multiple
  >
    <template v-slot:item="{ item }"
      ><VListItem class="text-center" @click="addUser(item.raw)">
        <VAvatar size="40px" color="black" variant="outlined"
          ><VImg alt="profile avatar" :src="item.raw.avatar" />
        </VAvatar>
        <VListItemTitle
          >{{ item.raw.firstName }} {{ item.raw.lastName }}</VListItemTitle
        >
        <VListItemSubtitle>{{ item.raw.username }}</VListItemSubtitle>
      </VListItem>
    </template>
    <template v-slot:chip="{ item }">
      <VChip
        @click:close="removeUser(item.raw)"
        :text="item.raw.username"
      ></VChip>
    </template>
  </VAutocomplete>
</template>

In the bottom segment of the template, where the VChip component is utilized, I am adept at adequately managing the @click:close event. However, in this context, the VChip can also be closed by selecting them using arrow keys and pressing backspace within the VAutocomplete edit mode.

I have experimented with various options such as @vnode-before-unmount, @keydown.backspace, and @update:model-value events, but none have yielded the desired result. An important observation is that @vnode-before-unmount event indeed triggers successfully and calls the removeUser function accurately. However, peculiarly, the scope of the component does not persist through the process. In fact, the select reference is empty when the handler is invoked through this event, whereas it is properly populated when triggered via the @click:close event.

I appreciate your assistance in advance.

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

Firestore is failing to accept incoming data when the setDoc method is employed

I am encountering an issue with my app's connectivity to the Firestore database when attempting to utilize setDoc. The database is successfully operational for next-auth, creating records as intended. However, the problem arises when trying to enable ...

Troubleshooting React-Redux: Button click not triggering action dispatch

I am facing an issue where my action is not being dispatched on button click. I have checked all the relevant files including action, reducer, root reducer, configStore, Index, and Component to find the problem. If anyone can help me troubleshoot why my a ...

Learn how to transform a raw readme file into an HTML formatted document using AngularJS, after retrieving it from GitHub

Can someone help me figure out how to format each line of the README.MD raw file into an HTML document using the controller below? angular.module('ExampleApp', []) .controller('ExampleController', function($scope, Slim,$sce) { ...

"Troubleshooting: Why is the JavaScript canvas.toDataURL method returning an

While I know this question has been asked multiple times before, I still haven't been able to find a solution. My goal is to take an image, rotate it, and place it in an HTML canvas. To achieve this, I am utilizing another canvas where I rotate the i ...

Issues with routing in Node.js using Express

This is my first attempt at programming. I am currently in the process of setting up routing in the following way: var indexRouter = require('./routes/index'); var loginRouter = require('./routes/login'); app.use('/', indexRo ...

Enhance user interactivity by incorporating dynamic checkboxes, radio buttons, checkbox groups, and radio button groups using Ext

Hello to all the amazing folks at Stack Overflow! I've tried searching for a solution to this issue on Stack Overflow, but I couldn't find anything helpful. Here is my model: Ext.define('soru', { extend: 'Ext.data.Model' ...

Display the header.vue component in Nuxt with data fetched from the store

My header.vue file contains user information retrieved from the store (vuex), such as username and profile image. Everything functions properly when navigating through the website by clicking on links. However, when the page is reloaded, the header with ...

What is the best way for a Vue component to update a list in a different component that it's not directly related to?

There are two main components in my project: <filter-controls></filter-controls> <data-list></data-list> The <data-list> component contains a list of items, such as ingredients, that can be filtered based on user input. Me ...

The URI entered is not valid: The parsing of the hostname failed. Electron Builder

Having an issue while trying to build an electron app using squirrel, even though the iconUrl is valid. Here is my package.json configuration: "squirrelWindows": { "iconUrl": "http://95.85.39.111:5005/skylog.ico" }, Error message received: An unhand ...

Types for Vue libraries

I am in the process of developing a Vue library as an NPM package with the intention of making it available for use in other projects. The main entry point is main.ts, which exposes a plugin and some commonly used functions. Here's a simplified examp ...

Encountered an error while trying to find the Node JavaScript view

Whenever I attempt to render the URL for displaying index.js in the browser, an error arises: **Error:** Failed to locate view "index" in views directory "D:\NodeJs\Example\5expressnodjsexmp\views" Below is my application code: //Hea ...

Tips for assigning a unique number or identifier to each element in vue js?

In my situation, I am working on creating a dynamic form (similar to a to-do list app) in separate components. I need to make sure each element (div) has a unique identifier for accessibility and other actions. However, when I try to use an increment metho ...

What is the best way to integrate JavaScript with my HTML command box?

I'm having some trouble with an HTML command box that is supposed to execute commands like changing stylesheets and other tasks. I thought I had everything set up correctly, but it doesn't seem to be working at all. Below is the HTML code with th ...

Creating an interactive map on an image using HTML and drawing circles

I've been experimenting with drawing circles on images using the map property in HTML. I have an image set up, and when clicking on the image in JavaScript, I'm adding the area coordinates for the map property. However, I keep encountering a null ...

What is the purpose of utilizing "({ })" syntax in jQuery?

What is the purpose of using ({ }) in this context? Does it involve delegation? Can you explain the significance of utilizing this syntax? What elements are being encapsulated within it? For instance: $.ajaxSetup ({ // <-- HERE error: fError, ...

Using jQuery to select a specific checkbox from a group of checkboxes with identical IDs

There is an issue with multiple checkboxes having the same ID in an asp.net repeater control. Users can select either email or phone against each record in the repeater rows. In the example below, there are two rows. If you select the email icon in the fi ...

Binding arguments to child functions within Vue components

When working with React, it's a common practice to bind parameters for child components in the following manner: <Child onChange={e => doThing(complex.variable.inParentScope[3], e.target.value)} foo="bar" /> In Vue, I want to ach ...

Angular 2 Element Selection: Dealing with Unrendered Elements

This form consists of three input fields: <div> <input *ngIf = "showInputs" #input1 (change)="onTfChnage(input2)" type="text"/> <input *ngIf = "showInputs" #input2 (change)="onTfChnage(input3)" type="text"/> <input *ngIf = "showInp ...

How can we show pictures when a user clicks?

After creating a model for displaying images in a modal when clicked by the user, I encountered an issue. Whenever I try to access the images from the gallery within the modal content, it only displays a blank popup. I want the pictures from the image gall ...

Ways to continuously refresh the display in AngularJS

There are 2 div elements below, and I need to display only one of them depending on whether the doStuff() function is triggered in the controller when a specific anchor element is clicked. <div ng-controller='myController'> <div ng- ...