What is the best way to update Vue-Multiselect dropdown choices?

I recently started using vue js and I decided to incorporate the vue-multiselect plugin. I successfully integrated the plugin in vue js with inertia js and laravel on the backend. However, I encountered an issue where the dropdown content does not update when receiving a response from the server side during a search.

let selectedUser = ref(props.filters.selectedUser);
let selectedCustomer = ref('');
let users = [];
let customerSelected = (selected={}) => { selectedCustomer = selected;asyncFind();};

let asyncFind = (find='') => {
    var url= window.location.href;
    url = url.split("/logs");
    if(selectedCustomer.id !=undefined)
    {
        window.axios.get(url[0]+'/custusers', { params: { search: find, customer:selectedCustomer.id } })
                    .then(response => {
                        users = response.data;
                    })
                    .catch(error => {
                    console.log(error);
                    });
    }
};

Here is the HTML code:

<multiselect v-model="selectedUser" 
             :value="selectedUser"
             :options="users"
             label="text" 
             track-by="text" 
             placeholder="Type to search" 
             open-direction="bottom"    
             @search-change="asyncFind">
</multiselect>

The server response data looks like this:

[
   {
      "id":10490,
      "text":"kashif"
   },
   {
      "id":10491,
      "text":"kashif"
   },
   ...
]

I have attempted to find solutions in various forums but haven't been able to find a resolution yet.

Answer №1

users variable must be made reactive as well:

// ...
let users = ref([]);

Make sure to keep it updated:

// ...
window.axios.get(url[0]+'/custusers', { params: { search: find, customer:selectedCustomer.id } })
    .then(response => {
        users.value = response.data;
})

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 power of Scoped CSS with Bootstrap/Bootstrap-Vue Integration

I'm currently working on a chrome extension and utilizing Bootstrap-Vue in my Vue files. I have imported bootstrap/bootstrap-vue into my js file, but the styling is being applied globally. Is there a way to scope the Bootstrap only onto specific inser ...

Issues encountered when utilizing the each method to retrieve ajax data

Here is the issue I am facing: I am attempting to apply a red border to fields that are empty using the jQuery code below: $("#frmId input, #frmId select, #frmId textarea").each(function(){ if($(this).val() == ""){ $(this).css('borde ...

There is an abundance of brief PHP documents

After conducting some initial research, I have realized that I need more information on the topic at hand. My interactive website relies on ajax calls to retrieve data from the server. Authenticated users engage with this data through various actions, whic ...

Adding animation to the CSS property of display:none changing to display:block using JavaScript

Recently, I came across a code snippet that handles the visibility of a button using JavaScript. The code includes both HTML and JavaScript portions. HTML <div id="butStyle"> <button id="langBut">Language</button> ...

Simulating Cordova plugin functionality during unit testing

I have a code snippet that I need to test in my controller: $scope.fbLogin = function() { console.log('Start FB login'); facebookConnectPlugin.login(["public_profile", "email", "user_friends"], FacebookServices.fbLoginSuccess, FacebookServic ...

Setting up a pivot table while inserting data into the database using Laravel 8

Is there a way to automatically insert a pivot table in Laravel 8 whenever I insert data into the counselings table? I have a Model Counseling with a many-to-many relationship with the Problem model. Input form https://i.sstatic.net/LSWHg.png counseling ...

Ways to show the existing value of a <select> in a label without altering the function

I currently have a label that changes to display the selected option from a dynamic select dropdown, but it only updates when the selection is changed. I would like it to also display the current value when the page first loads. I attempted to change &apos ...

JS unable to insert new row in table

I checked the input value before submitting it in the form and confirmed that it is correct, returning as a string.enter image description here const saveList = () => { const inputListNameText = inputListName.value; fetch('/api/lists' ...

Retrieve the value of the input type="file" when multiple files have been selected

Similar Query: Extracting file names from a multi-file upload control using JavaScript With HTML5 input type="file", users can select multiple files by adding the attribute multiple="multiple" : <input type="file" multiple="multiple" /> My que ...

Changing the color of a single mesh during rendering

My project consists of a grid with boxes, similar to the example seen at . I have implemented a hover state where the background turns gray when a box is hovered over. However, if there are multiple boxes on the grid and I try to change the background colo ...

Utilizing Node.js and Express to call a function twice - once with the complete req.body and once with an empty body

Trying to articulate this may be a bit challenging, but I'll give it my best shot. I have an iOS app and Android app that both access the same node.js app through their respective web views. The iOS version is able to open the node.js app without any ...

Looking for Efficiency in Basic JavaScript Arithmetic Operations

I'm having trouble figuring out how to display a total price after a selection is made. My goal is to take the selected value, multiply it by 100, and then use the updateTotal function to show the total. // Gather Data & Prices for Updating Dynamic P ...

Using Laravel 4 for dynamic pagination via AJAX requests

My controller has a function that is supposed to return a paginated set of items. I am using the same method as in all my other controllers (where it works perfectly), but for some reason, I am getting back an empty object. Here is the code for the functio ...

What is the best way to incorporate checkbox properties to monitor updates on individual rows in a table without relying on the Grid object or jQuery.Data(Input)?

Is there a way to perform form requests selectively on changed lines without relying on Grid or jQuery.Data(input) logic? Because the program is outdated, AJAX isn't suitable for this scenario as I don't want each line triggering a change event ...

Transitioning from the Homepage to the Posts page triggered a problem due to the impact of jQuery code used on the Homepage

Recently, I integrated some jQuery code into my react code to create a fading effect on the home page components when scrolling. While it works perfectly on the homepage, I encountered an error when navigating to another page such as the 'all posts&ap ...

Scope binding is successful, but accessing the array is only possible after adding an Alert() function

Within my Angular controller, I'm utilizing the SharePoint JavaScript Object Model to fetch data from the Taxonomy (term store). Due to SharePoint's JSOM not being a conventional Angular function that can be easily understood by the scope, I util ...

Tips for retrieving the value when a button is clicked in AngularJS

Looking for assistance on retrieving the selected value in AngularJS when a button is clicked. Below is the code I am currently using: <div class="form-inline"> <div class="form-group"> <select class="form-control" data-n ...

Is it possible to divide a text string into distinct arrays using spaces?

One method I am familiar with for splitting a string involves using the .split() method, like so: function split(txt) { return txt.split(' '); } When executed, this function would return ['hello', 'world'] if provided wi ...

Tips for ensuring that divs resize to match the container while preserving their original proportions:

#container { height: 500px; width: 500px; background-color: blue; } #container>div { background-color: rgb(36, 209, 13); height: 100px; } #one { width: 1000px; } #two { width: 800px; } <div id="container"> <div id="one">&l ...

Dynamically loading custom directive by assigning it to the controller's scope

I need help with dynamically loading my custom directive when a button is clicked. I am making an AJAX call to retrieve the directive's HTML and then compiling the response to assign it to a controller scope variable. However, the corresponding templa ...