I’m trying to add a simple ‘Select All’ function to some multi select menus. I’ve tried numerous javascript/jquery scripts but none of them have any effect.
I’m wondering if the way the menu is implemented in Wappler is different somehow - maybe the dmx-bind:options are preventing the script from working?
Copy the specified script (preferably somewhere at the bottom of the page) in the script tag. Be sure to replace the ID of the select component that you are using with your own inside the script:
It does not matter what you will use to control the selection of a button or link, it is important that they use a static event rather than a dynamic one. In a static event, specify the function that you refer to when you click:
@Mr.Rubi - it seems when you make the select component dynamic something prevents the script from working - it works with static options but not using a data source.
I’ve created an example here - both select components are using the same script. The static version works but the dynamic one doesn’t.
Maybe it’s something to do with the dmx-bind:options, i.e. the way the select component is being populated - I have no clue.
The problem is actually very simple. But I myself used to come across it very often and could not understand what was the matter. The fact is that if you look at the logic of the script, you can see that it creates an array of select_ids. After that, the $(document).ready event is listened to. As soon as the document is ready, a function is run that iterates through all the option indexes that are included in the select component and adds them to the select_ids array. However, since you use dynamic data for the selection options, they arrive later than the $(document).ready event. In this connection, dynamic variants do not have time to get into the DOM when the array filling function is started.
The easiest way that came to my mind for this situation is to redo the script a little. I moved the creation of the array, its filling, and the selection of the select options into one function: