Exploring the power of Vue.js: Leveraging the onChange feature with TomSelect

How can I implement onChange with TomSelect in my code?

<TomSelect
            :disabled="disableForm"
              v-model="wareHouse.agent.id"
              :onChange="changeAgentData"
              class="w-full"
            >
              <option value="">No Agent</option>
              <template v-for="(business, indexKey) in company.agentCompanies">
                <option v-if="business.companyType.includes('Shipper')" :key="indexKey" :value="business.id">{{business.name}}</option>
              </template>
              
            </TomSelect>

The current implementation is not working as expected. The changeAgentData function is not being triggered. I have tried using @change, change, and changed but none of them worked.

Answer №1

Not quite sure what tomSelect is - whether it's a custom component you've created or from a library.

Regardless, in order for @change to work, you need to either set up this event yourself or ensure that the library has a trigger setup for it (refer to the documentation of the component you're using in that case).

If you're not clear on how to do this, you can use a watcher instead. Since your v-model uses wareHouse.agent.id, it seems like you want to take action when this property changes.

watch: {
 'wareHouse.agent.id'(newId) {
   this.changeAgentData(newId)
 }
}

Each time a user selects a new option, the v-model updates the value and triggers the watcher function. https://vuejs.org/guide/essentials/watchers.html#basic-example

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

Utilizing the index of a generic type within TypeScript

I am attempting to design generic message types that become increasingly specific, with the most precise type being inferred during the function call or class creation. Consider the following code snippet: type MessageHeaderType = 'REQUEST'|&apo ...

Creating double the mesh in THREE.js by utilizing identical vectors as their position coordinates

Recently, I upgraded from r67 to r69 in ThreeJS and now facing issues with referencing the positions of objects to a single vector. Prior to the update, this code snippet worked fine: var vector = new THREE.Vector3(50, 50, 50); _Mesh1.position = vector; ...

Crystal-clear TextField component in Office UI Fabric

Seeking advice on how to clear a masked text field from Office UI Fabric using a button. Does anyone have a solution for this? I attempted to set the value using a state, but unfortunately, it did not work as expected. ...

Alter the style of a div by clicking on a button

Can the background image of a div be changed by selecting a button outside of the div? For example: HTML <div id="change"></div> <div id="buttons"> <button class="button1">this</button> <button class="button2"> ...

Iterate through an array while only mapping X number of elements during each iteration

Currently, I am working on a project that involves creating a grid of client logos using Tailwind CSS, react, and GSAP. The paths to the client logos are fetched from a JSON file. Since the list of client logos is quite lengthy, I decided it would be inter ...

utilizing a pair of API requests within a personalized Alexa skill

I posted a question about integrating Alexa with the Steam custom skill API here, but I realize it might be too detailed for some to read through. In essence, my main question is: Can you make two separate API calls within the same block of JS code while ...

Webpack compilation results in missing SVG icons display

As a newbie in web application development, I find myself in the final stages of my project. My current challenge involves bundling the entire project using webpack, and it's mostly smooth sailing except for one hiccup with my SVG icons. The issue se ...

Alternative options in Javascript for event listeners

Apologies if it seems like I'm asking for opinions, I could use some clarification. I'm curious as to why it's necessary to replace attributes such as onclick with anonymous functions. What benefits does this provide? For instance, if I ha ...

Retrieved information from the API patch

Hello, I'm a beginner looking to work on a practice project. My current task involves "patching" data fetched from an API. The JSON file structure is as follows: { "classes": [ { "title": "Office Syndrome", ...

Having trouble updating the default value in a react-select field

I'm currently utilizing redux-form along with a custom component that integrates react-select. The dropdown I created allows for pre-filled options and the ability to input custom values. I am specifically using the "creatable" component from react-s ...

Reminder popups on ASP.Net webforms that appear every five minutes

Is there a way to display a reminder popup with the details of upcoming meetings every five minutes before they start, 30 minutes prior? I attempted to use window.setInterval in my application's master page within $(document).ready. However, a problem ...

Pull out a collection from an entity

I'm struggling with retrieving an array from within an object. The structure is shown below: [] 0: Array(4) 0: 0 1: 5 2: 500 3: (5) [{…}, {…}, {…}, {…}, {…}] Despite attempting methods like using object.keys, for loop ...

standards for matching patterns (such as .gitignore)

Throughout my experience, I have utilized various tools designed to search a codebase for specific files and then carry out operations on those files. One example is test libraries that identify all the necessary files for execution. Another common tool is ...

Guide to setting up sub-routes in fastify

Currently, I am incorporating fastify as the web framework for my nodejs project. My aim is to organize and call all routes from a specific directory while having a base route established in the main JS file, similar to how it's done in express. Despi ...

Sorry, Vue DevTools inspection cannot be accessed at the moment

Using laravel 5.2 and my Package.json file contains: { "private": true, "scripts": { "prod": "gulp --production", "dev": "gulp watch" }, "devDependencies": { "bootstrap-sass": "^3.0.0", "gulp": "^3.9.1", "laravel-elixir": "^5. ...

Retrieving items from an array within a MongoDB aggregate operation based on specific criteria for fields at the same level

After analyzing the data provided, I am seeking a way to retrieve objects from the od array based on specific conditions. Additionally, I aim to extract the em and name fields as well. Although I lack extensive knowledge on MongoDB's aggregate functi ...

Where is the correct location to import the Firestore `Query` type from within Cloud Functions?

I am struggling to import the Query type from Firebase Firestore in one of my TypeScript files. I have tried looking for it in the firebase-admin package without success, and when I attempted to use @firebase/firestore-types (which is not recommended as ty ...

Creating a "select all" feature in an HTML multiple select box with jQuery - a step-by-step guide

I'm currently working on an HTML form that includes a multiple select box. I am looking to create a "select all" option within the multiple select box so that when a user clicks on that option, all other options in the select box are automatically sel ...

Some suggestions for updating two div elements using only one Ajax response

My website features a signin() button that I want to enhance with ajax functionality. When the button is clicked, I need it to update two divs: one displaying a personalized welcome message, and the other showcasing a statistics table in a different locati ...

What is the antonym of 'appear' when it comes to Vue transitions?

I’m currently working on a modal component that utilizes the 'v-if' attribute to determine its visibility. In the Vue documentation, it mentions using 'appear' for transitions (https://vuejs.org/guide/built-ins/transition.html#transi ...