angular-ui / ui-select2

AngularJS wrapper for select2 (deprecated, use angular-ui/ui-select)
https://github.com/angular-ui/ui-select
MIT License
596 stars 443 forks source link

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

Open sensugaz opened 7 years ago

sensugaz commented 7 years ago

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 commented 7 years ago

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

beta1007 commented 6 years ago

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 commented 6 years ago

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

spinningcat commented 6 years ago

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

it breaks select2 in my side