The on-change event of a Vue component's (select) does not trigger when the value is set using an external method

I have a Vue component called Select and I am defining it as a template. The data and props for the component are already set up.

var MyComponent = Vue.component('my-component',{

          template: "<select v-on:change=\"onAppSelected\"\n"+ 
          "v-model:value=\"appId\">        \n"+
          "<option v-for=\"appChoice in appChoices\" \n"+
          "v-bind:value=\"appChoice.id\">{{appChoice.name}}\n"+
          "</option>\n"+
          "</select>",
  
          methods: {
            onAppSelected:function(event){
              console.log("On Change Called:", this.item.serial)
              console.log("Event Target:",event.target.value)      
            },
            setValue: function(selValue) {
              this.appId = selValue;      
            },
          }, 
        });

The function onAppSelected is defined in the template using v-on:change, and it is triggered when an option is manually selected from the dropdown.

However, the onAppSelected function does not get triggered if the value of the select is set programmatically using the setValue method.

The setValue method is called from an external button.

The jQuery library's .trigger("change") method also does not help in this case.

Here is the full code on jsFiddle

A link to the complete implementation on jsFiddle has been provided for testing purposes. Please check the output in the console.

Can anyone offer assistance with this issue? Thank you in advance for taking the time to read about my problem.

Answer №1

According to MDN,

The event known as "change" occurs for <input>, <select>, and <textarea> elements when a user makes a modification to the value of the element. Unlike the input event, the change event does not necessarily occur for each alteration made to an element's value.

This implies that the change event is only activated when the value is actually modified by the user. It will not be triggered if the user selects the same value again.

To detect changes, you can use the "watch" function: JSFiddle

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

Is there a Vue library for page transitions that mimics the effect of Flutter Hero?

Check out the Vue Hero Transition package here. Explore the Vue Hero package on NPM. After reviewing various hero animation packages, I believe these two are worth mentioning. However, is there a library that receives more recognition based on star rati ...

Updating the content of a file on an iPhone

Is there a way to update the entire document content with a response from an ajax request? I've tested out using document.body.innerHTML and document.write(), which both work on desktop Safari. However, I'm looking for a solution that will also ...

Sencha applications experience a decrease in rendering speed on the user interface thread

I am currently developing a sencha web app using sencha touch 2.2.1. Within my application, there is a screen that contains a container with multiple panels. Each panel consists of two components - a top panel and an inner panel. Upon page initialization, ...

Having trouble with your HTML iFrame not functioning properly?

My code is not working as expected and I'm puzzled by it. It was working fine yesterday but now it's giving me trouble. <iframe allowfullscreen="" allowtransparency="true" frameborder="0" height="2000" scrolling="no" src="http://www.google.co ...

Access the content of each cell in a table using JavaScript

I need help with a scenario involving a table that has 4 rows, where the 4th row contains a textbox. When the "onchange" event of the textbox is activated, I want to retrieve the data from the cells in that specific row and transfer it to another table. It ...

The process for retrieving an environment variable within a pipeline and transferring it to a release pipeline

My program has an automatic build and deploy process. Here is the current workflow: When I push code to Git, Azure's build pipeline generates an artifact. This artifact is then picked up by Azure's Release pipeline, which deploys it to a Digi ...

Creating a comparison display using ng-repeat

I have a JSON file that contains revision and history information about a modified entity, including its old and new values. The diff is generated using the jsondiffpatch library and I have parsed it further to create the final JSON format for rendering. ...

"Exploring the wonders of AngularJS with JSON arrays containing objects

I am currently working on building an array of objects using AngularJS. Initially, I start with just one object. When the user clicks on a button, it adds another object to my array. The button functionality is as follows; HTML: <button ng-click="aj ...

The JS and CSS navigation menu suddenly ceased to function on the WebGL web page

Having some issues with my navigation menu that uses JS and CSS to create a slide-in style. It was working fine before, but now it's not working properly. Can't figure out if it's due to the webgl on the page or another reason. Visit: www.e ...

javascript Initiate JSON parsing with preset value

In order to parse JSON into a JavaScript object with data, I am providing a simple example below: var IsTrue = true; var Number = 9; var Object = { a : 1}; var Array = [10,6]; var jStr = '{"ask" : IsTrue, "value" : Number, "obj" : Object, "arr" : Ar ...

Node JS GET request using fetch stops displaying console outputs after a certain duration

I am currently working on building a calendar application using node, mongodb, html, css, and javascript. The main goal is to allow users to input dates as events which can be displayed dynamically. I am facing an issue where, upon trying to retrieve these ...

Error: The function **now.toUTCString** is not recognized and cannot be executed by HTMLButtonElement

While the JavaScript code runs smoothly without setting a time zone, I encountered an error when trying to display the Barbados time zone. The issue is related to now.toUTCString function throwing the following error message. How can I resolve this? Uncau ...

How can one effectively incorporate a 'toJson' function in TypeScript?

Does anyone know the best approach for adding a toJson function to a custom class? I've considered implementing functions like Foo.toJson, Foo.toJsonObject, or Foo.jsonify. Some examples suggest using a serializer. Is that necessary, or is there a mo ...

Matching numbers that begin with zero or are completely optional using Regex

Attempting to come up with a regex pattern that will allow the entry of the specified input into an HTML input field: The input must begin with 0 The input can be left empty and characters may be deleted by the user ^[^1-9]{0,1}[0-9\\s-\& ...

Transformation of CSS classes in React with Webpack

Have you ever noticed that when you inspect the Airbnb website, the classnames appear to be morphed into single alphanumeric names? What is the name of this technique and is it applied at the code level or build level? https://i.sstatic.net/qSiaj.jpg ...

A double click is required to enable the connected mouse press/release action

I have a section of code that is giving me some trouble: $('.toggle_box').each(function (){ var timeout, longtouch; $(this).bind('mousedown', function() { timeout = setTimeout(function() { longtouch = tru ...

jquery to create a fading effect for individual list items

I have a group of items listed, and I would like them to smoothly fade out while the next one fades in seamlessly. Below is the code I've been working on: document.ready(function(){ var list_slideshow = $("#site_slideshow_inner_text"); ...

What is the necessity for an additional item?

After exploring the Angular Bootstrap UI and focusing on the $modal service, I came across an intriguing discovery. In their demo at 'http://plnkr.co/edit/E5xYKPQwYtsLJUa6FxWt?p=preview', the controller attached to the popup window contains an i ...

Display the information contained within an array in a table using React

I have two arrays: one named formData and the other state array. const [formData, setFormData] = useState([]); let ure = [{}] useEffect(() => { axios .get("/api/listUre") .then((res) => { console.log(res.data ...

Working with nested loops for MongoDB arrays in a Node.js environment

Hi there, I'm fairly new to exploring Node.js and Mongodb. Currently, I am in the process of creating a roster system that allows only two users/employees to work on a specific shift. The shifts are categorized into 'day' and 'night&apo ...