Implementing an OnChange Event for a Multi-Select Feature in a Vue.js Application

Here is the HTML code for my multi-select input:

<select id="invitees_list1" class="form-select" multiple name="multi">
    @foreach ($seatedTable->invitees as $invitee)
         <option>
            {{ $invitee['name'] }}
           </option>
       @endforeach

  </select>

And here is the Vue.js code:

<script src="{{ URL::asset('assets/admin/app-assets/js/scripts/vue2.min.js') }}"></script>
     <script>
         const app = new Vue({
             el: '#filtersContainer',
             data: {
                 invitees: [],
                 selectedInviteeIds: [],
                 inviteesList: [],
                 selectedTableInfo: null,
                 eventTables: [],
                 newTableName: "",
                 totalChairNumberEntered: 0,
                 confirmedInviteesRoute: "{{ route('invitee_tables.confirmed_invitees', $event) }}",
                 selectedInviteesRoute: "{{ route('invitee_tables.assignModalData', $event) }}",
                 assignTableRoute: "{{ route('invitee_tables.assign', $event) }}",
                 isDisabled: false
             },
             created() {
                 axios.get(this.confirmedInviteesRoute)
                     .then(({
                         data
                     }) => {
                         if (data?.status) {
                             this.invitees = data?.data || []
                         }
                     })
                     .catch((err) => console.log(err))
             },
             mounted() {
                 $("#name_filter").select2()
                 $('#side_filter').select2()
                 $('#caller_filter').select2()
                 $('#relation_filter').select2()
                 $('#invitees_list').select2()
                 $('#invitees_list1').select2()

                 $('#invitees_list1').show()

                 $("#invitees_list").show()

             },

I'm looking to capture and trigger an event whenever the value of the multi-select input changes. I've attempted using JavaScript events, but it has not worked as expected.

Answer №1

To activate a function every time the multi-select input is modified, you can utilize the @change directive in Vue.js.

<select id="invitees_list1" class="form-select" multiple name="multi" v-model="selectedInviteeIds" @change="handleMultiSelectChange">
    @foreach ($seatedTable->invitees as $invitee)
        <option :value="{{ $invitee['id'] }}">
            {{ $invitee['name'] }}
        </option>
    @endforeach
</select>

Vue.js

const app = new Vue({

    // code

    methods: {
        handleMultiSelectChange() {
            // This method gets executed upon change in the multi-select input
            console.log('Selected Invitee IDs:', this.selectedInviteeIds);

            // Insert your custom operations or trigger an event here
            // For instance, emitting a custom event is an option
            this.$emit('multiSelectChanged', this.selectedInviteeIds);
        }
    }
}); 

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

Exploring CountUp functionality with Vue framework

I'm still getting the hang of Vue and recently completed my first project following a tutorial. This project is my first solo endeavor. Currently, I am working on a basic page to display the scores between two teams. The scores are retrieved from an ...

Is it possible to trigger Material UI Dialogs from the Parent Component?

Looking for help on how to open two separate Material UI dialogs (Terms & Privacy) from their parent component, a Material UI 'simple menu'. I have already imported and nested them in the parent component, but struggling to figure out how to trig ...

Is there a way to create a function that can show the pathway on the Browser Console?

I am looking to create a function that will show the path in the Browser Console when a link in the menu of a sub-category is clicked. The menu setup resembles this () on an e-commerce website. For instance: Perfume => ForMen => Cologne How can I r ...

Optimizing Wordpress by Efficiently Enqueueing Javascript

As a beginner with a WordPress website, I am aware that in order to execute scripts on a WordPress page, they need to be enqueued in the functions.php file. However, I'm unsure about the correct process for this. The specific JavaScript file I want t ...

A declaration file for the 'vuelidate' module could not be located

When I was following the installation instructions for Vuelidate in Vuejs (), I encountered a warning message at this line: import Vuelidate from 'vuelidate' The warning states: There seems to be an issue with finding a declaration file for t ...

Error in NVD3 causing charts to be inaccurately rendered

While utilizing a stacked area chart in the Stacked display mode, there appears to be an issue with the shading under the graph, particularly on the left side of the displayed plot below. We are currently working with d3 v3.4.9 and nvd3 v1.1.15b. Do you ...

Exploring the world of Node.js, JSON, SQL, and database tables

Hello everyone, I have been working on a project using Node.js and Express framework. My current goal is to create a client-side page that allows users to input form data into a MySQL database. I have managed to successfully insert and retrieve data from ...

Creating a universal variable in Laravel with just one word

There's something I'm not sure about, I'd like to create a variable called @ads in the view files so that whenever @ads is used, it would call a specific div element: <div class="ads"> @if(condition) some block of codes... ...

Using a temporary variable within a Vue loop

Currently, I am utilizing Vue along with Vuetify to create a menu containing links using the treeview component. The data source I'm working with is a nested JSON structure. The issue I am facing is regarding linking the parent "to" with its children ...

Utilizing IISNode and/or nodemon for efficient node.js development on Windows platform

For my node.js application running on Windows, I currently utilize IISNode both locally during development and on production hosting. Would incorporating nodemon (or a comparable module that monitors file changes and restarts node.exe when necessary) pro ...

Exploring the power of React Leaflet and the exciting possibilities of React Leaflet

I'm currently in the process of implementing the draw functions on a leaflet map. I started off by creating a new app with just react-leaflet installed. I used npx create-react-app and installed the following packages: npm install react react-dom lea ...

Achieving a Transparent Flash overlay on a website without hindering its usability (attention, interaction, form submissions, etc.)

Currently, we are attempting to overlay a transparent flash on top of an iframe which loads external websites. Is there a method to configure the page in a way that allows the transparent flash to be displayed while still allowing interaction with the und ...

Prevent the box from closing automatically after submitting a form using jQuery

Despite my efforts to keep a simple dialog box open after submitting a form, it continues to close. I tried using the preventDefault method in jQuery, but it didn't solve the issue. Below is the code snippet: $(document).ready(function(e) { $(&apo ...

How can I detect when an image is loaded in a specific container division using jQuery?

I have a container with multiple images inside, and I would like to capture an event each time an image finishes loading. For example: <div id="container"> <img src="..." /> <img src="..." /> <img src="..." /> ...

What could be the reason my Backbone view is failing to render?

Can anyone help me troubleshoot why this template isn't rendering properly in my backbone views? Any insights would be greatly appreciated! Below, I've included the code from my jade file for the views and the main.js file for the backbone js scr ...

Retrieve recently appended DOM elements following the invocation of createComponent on a ViewContainerRef

I have a current function in my code that dynamically creates components and then generates a table of contents once the components are added to the DOM. This service retrieves all h3 elements from the DOM to include in the table of contents: generateDy ...

Struggling to locate images in Three.js

I'm facing a challenge with my Vue Cli app where I am attempting to use Three.js for rendering 3D objects within it. The issue arises when I attempt to load an image to utilize as a texture. let scene = new Three.Scene(); const spaceTexture = new Th ...

Converting PPT files to PDF or PNG using Node.js

Are there any options available for converting ppt files to pdf or png without relying on specific operating system dependencies? I need to convert a ppt file to png, but all the current packages I have tried require tools like LibreOffice or ImageMagick ...

Interfacing Highcharts with Angular for seamless data binding across series

I am fairly new to using highcharts and I am having difficulty binding my data into the series parameter. In my controller, I have an array of objects that I want to display (when I use console.log, I can see that they are all properly there) this.plotDa ...

Sometimes, the `undefined` TypeError can unexpectedly pop up while making Ajax calls

Here is my issue with AJAX request and response: I have around 85 HTML pages that all use the same AJAX request. However, when working with these files, I sometimes encounter the following error. AJAX $(document).ready(function(){ localStorage.setIte ...