Search code examples
javascriptjqueryjquery-select2jquery-select2-4

Can't retrieve, reset or update select2 options


Please see this jsfiddle: https://jsfiddle.net/L1tns1yh/1/

First, it doesn't retrieve proper .select2('data')

Then, clicking the button doesn't reset the options, tried different ways I've found on the internets...


Solution

  • You could try the following, i dont realy like this solution but it works if you create a new select2:

    $button.click(function () {
      $('#select').select2('destroy').empty().select2({allowClear: true,
      placeholder: 'Placeholder...'});
    });