Nulji
Nulji

Reputation: 457

Update data with select2

I'm using select2.

I'm looking for a way to update my data array.

$('#add-users').select2({
    theme: 'bootstrap4',
    placeholder: 'Invite someone',
    allowClear: true,
    tokenSeparators: [',', ' '],
    data: users
});

On this one, I just need to update data from the select2 add-users. (Removing or adding elements that I want in it).

Upvotes: 2

Views: 894

Answers (1)

Clément Drouin
Clément Drouin

Reputation: 395

Actually, you can't update select2 You have to destroy it with

$('#myselect').empty().trigger('change');

or

$('#myselect').select2('destroy').trigger('change');

And then recreate it with your data

Upvotes: 2

Related Questions