Having difficulty choosing an item from a personalized autocomplete search bar in my Vue.js/Vuetify.js project

NOTE: I have opted not to use v-autocomplete or v-combobox due to their limitations in meeting my specific requirements.

I'm facing difficulties while setting up an autocomplete search bar. The search functionality works perfectly except for one minor issue - selecting an item. When hovering over an item, a hand cursor appears indicating its clickability. Upon clicking the item, an @click event should trigger a method, but unfortunately, nothing happens.

Identifying the root cause of the problem is clear to me, however finding a solution has been challenging. The issue arises from the following parts:

<v-text-field //here's the input
    ...
    @focus="isFocused = true" @blur="isFocused = false"
    ...
></v-text-field>

<v-list v-show="queried_cards.length && isFocused"> //this represents the list
    <v-list-item @click="setCard(card)" v-for="(card, index) in queried_cards" :item="card" :key="index">
        ...
    </v-list-item> 
</v-list>

In summary, according to the above code structure, I aim to display the list only if the array queried_cards is not empty and if the v-text-field is focused on. Concealing the list when clicking outside the text field aligns with the intended outcome. However, this behavior conflicts with the item selection functionality, as clicking on an item is equivalent to clicking out of the text field (triggering @blur). Consequently, the setCard() method fails to execute since the v-list disappears before the @click="setCard(card)" event.

This issue has been lingering as I hoped to find a resolution eventually. Unfortunately, I am currently overwhelmed by other project tasks.

To better illustrate my problem, I have created a codepen: https://codepen.io/chataolauj/pen/RwwYxBg?editors=1010

Answer №1

there seems to be an issue with the way you have set up the list display using

<v-list v-if="queried_cards.length && isFocused" class="pa-0 overflow-y-auto" max-height="300" two-line>

When you click on a list item, the isFocused property is set to false due to the @blur="isFocused=false" binding on the input field, causing it to disappear. You need to find a solution to keep isFocused true when selecting items.

A quick solution would be:

Bind a click function on your v-container (to hide the result list when the user clicks outside of the input or the list):

  <v-container fluid @click="checkHide">
    checkHide(e){
   // if clicked on input or list items, keep the list visible
      if(e.target.tagName ==="INPUT" || e.target.classList.contains("v-list-item__content")){
        this.isFocused = true
      }else{
// clicked outside, hide it
        this.isFocused = false
      }
    }

Remove the @blur binding from your input element.

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

The information is not appearing in the dropdown menu

The select tag for chapters is not displaying the result from the query properly. Instead of showing in the select tag, the chapter names are being displayed as echo statements. <!doctype html> <html> <head> <meta charset="utf-8"> ...

The initial ajax request may sometimes return as 'undefined' during its first call

I have been working on creating a text input help feature similar to a desktop using the datatable.in table with keyboard navigation. In order to achieve this, I am dynamically changing the data source and also altering the header column. I have been succe ...

Executing a single command using Yargs triggers the execution of multiple other commands simultaneously

I've been diving into learning nodejs and yargs, and I decided to apply my knowledge by creating a command-line based note-taking app. The structure of my project involves two files: app.js and utils.js. When I run app.js, it imports the functions fr ...

Utilizing Angular and Express for routing with the seamless integration of html5mode

I'm facing an issue with making angular and express routing work together with html5mode enabled. When I change state from '/' to my admins state, everything works fine until I refresh the page. Then I only get a json result of admins but my ...

Struggling with configuring a 'post' endpoint in an express server problem

My goal is to validate that my client is able to successfully post information to its server. I have configured a specific 'route' on my Express server for this purpose. // server.js this is the server for the PvdEnroll application. // var ex ...

Detecting when the Ctrl key is pressed while the mouse is hovering over an element in React

In my project, I have implemented a simple Grid that allows users to drag and drop items. The functionality I am trying to achieve is detecting when the mouse is positioned on the draggable icon and the user presses the Ctrl key. When this happens, I want ...

Encountering SCRIPT1014 and SCRIPT1002 errors within an Angular4 application when using Internet Explorer 11

My Angular 4 application runs perfectly in various browsers. However, when trying to launch it in Internet Explorer version 11, I encounter the following two errors: SCRIPT1014: Invalid character addScript.js (9,1) SCRIPT1002: Syntax error main.bundle.js ...

Tips for accessing the FormControlName of the field that has been modified in Angular reactive forms

My reactive form consists of more than 10 form controls and I currently have a subscription set up on the valueChanges observable to detect any changes. While this solution works well, the output always includes the entire form value object, which includ ...

React Component - Element with an undefined value

When I tried implementing an Ionic Modal as a React Component, I encountered the following error message: Type '({ onClose, tipo }: PropsWithChildren<{ onClose: any; tipo: number; }>) => Element | undefined' is not assignable to type & ...

Implementing Winston logging into a React JS project

I am looking to integrate Winston logging into my React application that was created using create-react-app. First, I installed Winston by running the following command: npm install winston Next, I imported Winston into my app.js file like so: import win ...

The footer seems to be losing its stickiness and not staying at the bottom when I

My goal is to create a sticky footer for my webpage. Once you click the add new sports button, a drawer slides out and the footer remains fixed at the bottom. However, as I scroll down the page, the footer moves up instead of staying in place. I have tried ...

Can JavaScript be used to update/override Prototype version 1.4 to version 1.7 on a different website?

(I'm uncertain about the best way to phrase this question, feel free to make changes). I am in the process of embedding a JS widget onto a different website that is using Prototype.js Version 1.4. I have incorporated jQuery into my widget and have it ...

Bootstrap 4 tabs function perfectly in pairs, but encounter issues when there are three of them

Having trouble with bootstrap4 tabs not working properly? They function well with 2 tabs using the code below: <div class="row"> <div class="col-12"> <ul class="nav nav-tabs" id="registration-picker-acc-select" role="tablist"> ...

Embracing JQuery for Frontend Development with Node.js

I'm currently enhancing my node.js skills by utilizing express, and I've encountered a situation that is causing me some confusion. Essentially, when a user requests a webpage and the backend sends them the HTML page, how can I incorporate a Java ...

Bookeo API allows only a maximum of 5 requests to be processed through Node.js

Greetings! I am excited to be posting my first question here, although I apologize in advance if anything appears unclear! My current project involves utilizing Bookeo's API to extract booking data from emails belonging to a tour company and transfer ...

Attempting to deactivate the bootstrap-fullscreen-select feature using JavaScript

Currently, I am in the process of developing a Python Flask server to manage a project that I have undertaken. While exploring different options, I came across bootstrap-fullscreen-select which turned out to be exactly what I needed for my control page. H ...

Does GIF animation operate on the same thread as JavaScript in all popular web browsers?

When my AJAX request is in progress, an animated GIF is displayed to show activity. However, I have noticed that the animation freezes while the response from the request is being processed by a script that heavily updates the DOM. After researching this ...

successive ajax requests

I am facing a challenge where I need to execute two separate ajax calls sequentially. The second call relies on the result of the first call for its data. Despite my efforts, I haven't been able to achieve the desired outcome. Here's what I have ...

The Java Selenium script encountered an illegal type error when trying to execute JavaScript through JavaScriptExecutor: driverFactory.CustomWebElement

I have a CustomWebDriver class that extends the functionality of JavascriptExecutor. Here is my implementation: @Override public Object executeScript(String script, Object... args) { return ((JavascriptExecutor) driver).executeScript(script, args); } ...

What might be causing the transition not to function properly within my Vue components?

I have been working on a Vue application where I have two interconnected components. One of them is named loginRegister.vue and its code is as follows: loginRegister.vue: <template> <BaseModal idBtn = ...