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 refresh the multiple-select with Jquery (or javascript) #62

Open
brunojimenezh opened this issue Jul 2, 2022 · 1 comment
Open

Comments

@brunojimenezh
Copy link

Hi,
I'm trying to empty and then fill again the multi-select via Ajax. I see the Ajax works for a common multi-select filed, but if it is already using multi.js, it stays the same. How can I refresh the content? I see the multi.js already has a refresh_select function, but I don't know how to call it. Tahnks in advance!

@lupainformatica
Copy link

I did this by removing all "a" inside "selected and non-selected" wrappers

$('.selected-wrapper a').remove();
$('.non-selected-wrapper a').remove();

And in ajax response I repopulated the original select list and all links "a" inside non-selected-wrapper

$.ajax({
    method: 'GET',
    url: `your-url-here`,
    success: function(response) { // response could be a json with id: value

          const available $('.non-selected-wrapper:first');
          
          let cont = 0;
          for (item in response) {
              let a = document.createElement('a');
                   a.setAttribute('tabindex', 0);
                   a.setAttribute('class', 'item');
                   a.setAttribute('role', 'button');
                   a.setAttribute('data-value', item);
                   a.setAttribute('multi-index', cont);
                   a.text = response[item];

               available.append(a);
          }
    })
    //... rest of your code
});

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

2 participants