Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dynamically add option value to an existing multiselect element that has data #1242

Open
mhguelleh opened this issue Sep 9, 2022 · 0 comments

Comments

@mhguelleh
Copy link

Hi, thanks for the wonderfull library.
But I am looking for a feature that I did not see in the docs.

Is there a way to add a newly created option to an existing multiselect element while preserving the data that's already present in the multiselect ?

For example, I have a multiselect that is initialized with an array of data on page load

  1. My array is filled like so:
const arrFillMultiSelectElement = arrDataDependencies?.map(data => (
    {
        "label": data.at(1)?.toString().trim() || "", // name
        "title": data.at(1)?.toString().trim() || "", // name
        "value": data.at(0)?.toString().trim() || "", // id
        "selected": false, 
        "disabled": false, 
        "attributes": null 
    }
)) || [];
  1. My multiselect element is initialized with the array like so:
    $(multiSelectElement).multiselect('dataprovider', arrFillMultiSelectElement);

  2. The multiselect is checked and some values are selected.

  3. But then a new value is added later in the HTML and I need to read and add that value to the multiselect (already contains data and values).

Right now, I can just do by destroying what's present and recreating the multiselect from scratch, which means I lose all information that was already checked within the multiselect.

Thanks for any help

@mhguelleh mhguelleh changed the title Dynamically add option value to an existing multiselect element that has data How to dynamically add option value to an existing multiselect element that has data Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant