Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

how fix 'select2' ('destroy') #305

Open
sensugaz opened this issue Apr 14, 2017 · 4 comments
Open

how fix 'select2' ('destroy') #305

sensugaz opened this issue Apr 14, 2017 · 4 comments

Comments

@sensugaz
Copy link

sensugaz commented Apr 14, 2017

I get error 'select2' ('destroy') when changing route edit how fix it.

The select2('destroy') method was called on an element that is not using Select2.
angular.js:14525 TypeError: Cannot read property 'destroy' of undefined
    at HTMLSelectElement.<anonymous> (select2.js:5685)
    at Function.each (jquery.js:362)
    at jQuery.fn.init.each (jquery.js:157)
    at jQuery.fn.init.$.fn.select2 (select2.js:5675)
    at HTMLSelectElement.<anonymous> (select2.js:175)
    at HTMLSelectElement.dispatch (jquery.js:5206)
    at HTMLSelectElement.elemData.handle (jquery.js:5014)
    at Object.trigger (jquery.js:8201)
    at jQuery.fn.init.triggerHandler (jquery.js:8275)
    at Function.jQuery.cleanData (angular.js:2028)
@nasri-zhang
Copy link

Try this.
$element.data('select2').destroy();

@beta1007
Copy link

beta1007 commented Aug 8, 2018

Starting on line 194 in select2.js, update the following lines of code to check if elem has class. If so, then call the appropriate functions.

   elm.bind("$destroy", function () {
      if (elm.hasClass('.select2-offscreen')) {
        elm.select2("destroy");
      }
    });
   attrs.$observe('disabled', function (value) {
      if (elm.hasClass('.select2-offscreen')) {
        elm.select2('enable', !value);
      }
    });

    attrs.$observe('readonly', function (value) {
      if (elm.hasClass('.select2-offscreen')) {
        elm.select2('readonly', !!value);
      }
    });

@blogazhar
Copy link

blogazhar commented Aug 27, 2018

var select = $(".select2").select2(); select.select2('destroy'); your data set select.select2();

@spinningcat
Copy link

$element.data('select2').destroy();

it breaks select2 in my side

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants