Issue with Vue3: Autocomplete text input field not triggering @input function

In my Vue3 component, I am utilizing the following code snippet:

<v-row
    v-for="(target, targetIndex) in targetModules"
    :key="targetIndex"
>
    <v-autocomplete
          v-model="targetModules[targetIndex]['modulName']"
          :items="moduleNamesAndEcts.map(module => module.name)"
          :rules="rules.text"
          label="Module"
          item-text="name"
          item-value="name"
          @input="(newModuleName) => updateEcts(newModuleName, targetIndex)"
        />
</v-row>

The function implemented is as follows:

const updateEcts = (newModuleName, targetIndex) => {
        console.log("HELLO!")
        const module = moduleNamesAndEcts.value.find(module => module.name === newModuleName);
        console.log(module.ects)
        if (module) {
            targetModules[targetIndex]['creditPoints'] = module.ects;
        }
    }

Strangely, it appears that updateEcts is not being called. The console.log statements are not executed. Even using @change didn't resolve this issue. What could be causing this problem?

Answer №1

There are no events such as input or change in the VAutocomplete API.

The recommended event to use is update:modelValue. You can find a list of all VAutocomplete API events here.

Your v-autocomplete component should be implemented like this:

<v-autocomplete
  v-model="targetModules[targetIndex]['modulName']"
  :items="moduleNamesAndEcts.map(module => module.name)"
  :rules="rules.text"
  label="Module"
  item-text="name"
  item-value="name"
  @update:modelValue="(newModuleName) => updateEcts(newModuleName, targetIndex)"
/>

To understand how update:modelValue works behind the scenes, refer to this explanation in Vue's official documentation.

It appears that this change was made in the third version of Vuetify, as discussed in this question

Answer №2

Success came when I made the switch from @input to @update:model-value:

@update:model-value="newModuleName => updateEcts(newModuleName, targetIndex)"

Answer №3

When working with Vue.js and utilizing v-model in conjunction with a custom component such as v-autocomplete, it is crucial for the component to emit an input event in order to update the value that is bound to it. It appears that the issue may stem from how the input event is being handled within the v-autocomplete component.

To resolve this issue, we need to verify that the v-autocomplete component correctly emits the input event when its value changes. Double-check that the v-autocomplete component is emitting the input event accurately along with the updated value.

<v-autocomplete
    v-model="targetModules[targetIndex]['modulName']"
    :items="moduleNamesAndEcts.map(module => module.name)"
    :rules="rules.text"
    label="Module"
    item-text="name"
    item-value="name"
    @input="(newModuleName) => updateEcts(newModuleName, targetIndex)"
/>

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

Having trouble with the functionality of Angular 2 filter and toggle features?

I recently developed a hamburger menu with a toggle function to display subcategories. Everything was working smoothly until I applied a filter. Once I search for a category using the filter, the toggle function stops working. Here is a snippet of my HTML ...

Building a collapsible toggle feature with an SVG icon using HTML and CSS

I am trying to swap a FontAwesome Icon with a Google Materials SVG Icon when a collapsible table button toggle is pressed (changing from a down arrow to an up arrow). I have been struggling to get the Google Material Icons code to work. How can I resolve t ...

Is it possible for me to replicate this full-screen flash animation using jQuery?

I need some guidance on how to create an animation similar to the one on http://flatuicolors.com without using flash. When you click a color on the website, it triggers a full screen animation with text. I'm not asking for code, just ideas on how to ...

Learn how to redirect email recipients to a separate page when they click on the email subject line

Currently, I am working on developing an inbox feature in PHP where it shows the Mail Id and Subject. When a user clicks on a specific division containing the mail id and subject, it should navigate to a new page in PHP that displays the body and attachmen ...

Tips for passing dynamic latitude and longitude values to a JavaScript function within an AngularJS framework

I am facing an issue with displaying a dynamic marker on Google Maps. I can show a static lat long marker, but I am struggling to pass dynamic lat long values to the function. How can I pass {{names.lat}}, {{names.longitude}} to the function so that I can ...

Dividing a string in Javascript with one identified character and an assortment of unknown characters

I need assistance with splitting a string by a specific character, such as a '/'. However, I also require the characters directly preceding the split character up to the space before them to be included in the result. For instance: let myStr = ...

What is the process for accessing getBoundingClientRect within the Vue Composition API?

While I understand that in Vue we can access template refs to use getBoundingClientRect() with the options API like this: const rect = this.$refs.image.$el.getBoundingClientRect(); I am now attempting to achieve the same using template refs within the com ...

Issue with Firefox: losing focus when clearing textbox value

Is there a way to clear the content of a search box (textbox) when clicked inside without using a watermark control? I am currently implementing the following function using the "onKeyDown" event: function clearTbSearch(tbSearch) { if (tbSearch ...

Creating an outlined effect on a transparent image in a canvas: step-by-step guide

Currently, I am working on creating transparent images using canvas in HTML5 and I would like to incorporate borders into them. The issue I'm facing is that the "Stroke" property does not consider the transparency of the image and applies it as if it ...

The change event for the select element is malfunctioning

Currently, I am deep diving into Nodejs with the second edition of the node cookbook. This book has caught my attention because it explains concepts using practical sample code, making it easier to grasp. The example code I am working on is related to Br ...

Mastering Kendo UI in Vue: The Ultimate Guide to Managing Child Checkboxes in TreeView

I am currently utilizing Telerik's Vue wrappers for Kendo UI. With the TreeView control, both the jQuery version and MVC wrappers have a feature that allows a property to automatically check child checkboxes when the parent checkbox is checked. ...

Is it possible to update the version of NPM?

Having an issue with installing packages for my React-Native project due to a NPM version error. How can I upgrade it? Currently using version 4 ...

I'm puzzled as to why there is a blank space in the false element statements

Hey there! I'm noticing a blank space on the page, and when I inspect it, I see this bindings={ "ng-reflect-ng-if": "false" }. It seems like I am getting some blank cards displayed. Here is an image showing what I mean: https://i. ...

Is there a way to incorporate Vue script in Laravel without utilizing Vue templates?

I have a question that may seem simple, but I'm curious about the best way to use vue script on pages individually without declaring it globally. For example, I have multiple pages in Laravel Blade such as the home page, category page, and product pag ...

When res.write is called before res.send, an error occurs

I'm struggling to figure out why I am getting an error with the following code. app.get("/", (req, res) => { res.write("Hello"); res.send(" World!"); }) // Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers afte ...

Switching players every two turns in a JavaScript AngularJS game

I have implemented an AngularJS score keeping game where players switch every two turns. The code works for one round, but I want to create a loop that keeps switching players. Check out my code below: app.controller('EventController', function( ...

Creating an object from select options in buildSelect methodWant to know how to convert

Based on the information from the http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config, the value property can be defined as an object: If set as an object, it should be defined as a pair value:name - editoptions:{value:{1:'One',2:&a ...

Tips for obtaining JavaScript output in Flask

function dragEnd(e) { if (activeItem !== null) { activeItem.initialX = activeItem.currentX; activeItem.initialY = activeItem.currentY; } var classname = activeItem.className; if (classname == "item one") ...

The behavior of React's SetState in an event handler varies when using mocked data versus data fetched from an API

Currently, I am replicating the same scenario with identical code in two different situations. With mocked data With data fetched from an API 1) The case with Mocked Data => https://codesandbox.io/s/select-demo-0e90s is functioning as expected The m ...

Revise the JSON format to be compatible with a JavaScript template library

My goal is to utilize JSON data for parsing a template using JavaScript. The Mustache library provides a solution as shown below: var output = $("#output"); // template stored in JS var as a string var templateString = '<div>'+ '< ...