The VueJS Chosen directive fails to refresh when new options are selected

Struggling to populate my jQuery Chosen dropdown field with AJAX data using VueJS. Unfortunately, when trying to update the values, the Chosen dropdown does not reflect the changes.

I've experimented with different approaches, including manually triggering

$('.cs-select').trigger("chosen:updated");
upon receiving the AJAX response. However, it seems that this method is ineffective due to VueJS requiring a few moments to parse the results for all dropdowns (I have around 20 dropdowns with identical values on a single page).

For example, adding the city Amsterdam does not appear in the JavaScript-enabled dropdown even after everything has loaded: http://jsfiddle.net/qfy6s9Lj/106/

Is there a simple solution to this issue? I believe resorting to setTimeout() is not the ideal approach.

Answer №1

Here is a potential solution that might require some effort on your part. Upgrading to Vue 1.0 would grant you access to a params value, allowing you to set up a watcher for when items are added to your cities array reference (https://vuejs.org/guide/custom-directive.html#params). However, in version 1.0, you must use v-for to list out the options since manual writing of option elements is necessary https://vuejs.org/guide/forms.html#Select

The reason it may not be functioning as expected could be due to lack of a listener for changes when the options change within your custom directive. The update function only detects modifications to the variable provided to v-chosen.

Depending on your requirements and timeline, upgrading directly to 2.0 could be an option. Although still in beta, 2.0 is close to official release. In 2.0, you would develop a custom component to manage plugins like so (https://github.com/vuejs/vue/blob/next/examples/select2/index.html) which was previously a directive in 1.0 and now a component in 2.0.

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

Guide for inserting personalized buttons onto a map with the Bing Maps 6.3 Ajax Control

Looking to enhance a Bing Map with custom buttons for more interactive functionality? I'm interested in creating a custom dashboard on the map that would allow users to toggle different information or colors displayed on specific pins or polygons by s ...

Is it possible to access a component's function from outside an ng-repeat in Angular 1.5?

Recently delved into learning Angular 1.5 components and testing out some fresh concepts, however, I'm struggling to wrap my head around this particular issue: Here's the code snippet from my Main: angular.module('myapp',[]) .contr ...

How can the Header of a get-request for an npm module be modified?

Currently, I am utilizing an npm module to perform an API request: const api_req = require('my-npm-module-that-makes-an-api-request'); However, I am seeking a way to modify the user-agent used for requests generated internally by the npm module ...

Events related to key press timing in HTML 5 canvas

Currently, I am developing a game similar to Stick Hero for Android using HTML5. I am working on the code that will capture the time of key press (specifically the right arrow key with ASCII 39) in JavaScript and expand a stick accordingly. <!doctype h ...

Performance issues may arise in React styled-components when the state changes frequently during mousemove events

My current challenge involves implementing a parallax animation using react hooks and styled-components, but I am facing performance issues. The constant rerenders of components seem to be causing janky animations rather than smooth ones. Here are the sty ...

Transmitting Several Pictures at Once Through WhatsApp-WebJS

I have encountered a challenge while attempting to send multiple images in a single WhatsApp message using the WhatsApp-WebJS library. Despite receiving a "success" confirmation without any errors, the images and message fail to appear on WhatsAp ...

Ways to address memory leakage issues in Angular

Is there a way to manually optimize the Garbage Collector by forcefully pushing variables into it? For example, if we have a root or global level variable in an Angular component that is no longer needed when switching to another page, how can we ensure it ...

What can you do with a 2D array and getElementsByTagName?

My current challenge involves trying to utilize JavaScript to access table cells by using the getElementsByTagName method. The end goal is to compare each cell in the array to a specific value and then change the background color of that cell based on the ...

InternJS - Unresolved TypeError: The undefined object does not have a property named 'readFile'

I am currently facing an issue with Intern.js during functional testing. The error mentioned in the title has me puzzled as I struggle to figure out how to successfully load json files through FS or require. Despite my best efforts and extensive searches o ...

Transferring AJAX response from Django to a PHP variable

When I use ajax to send a request to my django function, which generates a zip file and serves it to the user, everything works fine if I directly access the URL domain.com/django/builder/zipit/. However, when using ajax and the response is returned, ajax ...

Utilize Angular to inject an input from a component directly into the header of my application

I am looking to customize my Pages by injecting various components from different Pages/Components into the header. Specifically, I want to inject an Input search field from my content-component into the header Component. I initially attempted to use ng-Co ...

Having trouble with collision detection in Three.js?

I am currently working on creating a 3D Breakout game using three.js. Most of the collision detection for the walls is already implemented, but I'm facing difficulties with the collision against the paddle. Below is my code snippet: // A 3D breakout ...

Having trouble with Vuejs Ternary Operator or Conditional in v-bind-style?

Having some unexpected issues while trying to implement a style conditional for items in Vuejs. I have come across Stack Overflow posts on how to use a ternary, either through an interpolated string or a computed style object. I've attempted both met ...

swapping out a submit link for an indicating Ajax button

My form currently uses a submit button to retrieve results from a database and update a list view accordingly. If there are no results, a feedback message is displayed as expected. Now, I am looking to enhance the user experience by replacing the submit l ...

Error: The combination of 0 and .... is invalid and cannot be used as a function

I am currently in the process of developing a next.js application using Material-ui. I have been attempting to integrate material-ui into my project. Following guidance from the official GitHub page, I have copied the _app.js , _document.js , theme.js fil ...

Restricting the number of mat-chips in Angular and preventing the input from being disabled

Here is my recreation of a small portion of my project on StackBlitz. I am encountering 4 issues in this snippet: I aim to restrict the user to only one mat-chip. I attempted using [disabled]="selectedOption >=1", but I do not want to disable ...

How can I animate SVG paths to fade in and out sequentially?

My current code is causing the path to fade in/out all at once instead of one after the other var periodClass = jQuery(this).parent().attr("class"); jQuery("svg path").each(function(i) { var elem = jQuery(this); if (elem.hasClass(periodClass)) ...

Are there any situations in which subscribing to an RXJS Observable does not result in either a success or error response

I have a question rather than a problem to resolve. I am curious if there is a scenario where neither "Success" nor "Error" are triggered. When making a POST call to "/logout", the expected response is an HTTP status code of 200 with an empty body. impo ...

A guide to integrating OIDC through the vuex-oidc library within a Vue.js application

We are currently working on incorporating OIDC for user onboarding from our primary platform to our secondary platform When attempting to call the AutomaticSilentRenew function, we encounter the following error: Could there be something incorrect here? (Pl ...

Attempting to retrieve nested data, only to be met with an undefined response

I've been attempting to retrieve specific information by iterating through the SearchResult object like so: for (let productKey in SearchResult) { if (SearchResult.hasOwnProperty(productKey)) { products.push({ name ...