diff --git a/src/js/select2/utils.js b/src/js/select2/utils.js index 53d82f3d..4c96034a 100644 --- a/src/js/select2/utils.js +++ b/src/js/select2/utils.js @@ -332,6 +332,8 @@ define([ if (Utils.__cache[id] != null) { delete Utils.__cache[id]; } + + element.removeAttribute('data-select2-id'); }; return Utils; diff --git a/tests/unit-jq1.html b/tests/unit-jq1.html index 730b35db..1ef049c8 100644 --- a/tests/unit-jq1.html +++ b/tests/unit-jq1.html @@ -94,6 +94,7 @@ + diff --git a/tests/unit-jq2.html b/tests/unit-jq2.html index 6ff3b0c2..031f113c 100644 --- a/tests/unit-jq2.html +++ b/tests/unit-jq2.html @@ -94,6 +94,7 @@ + diff --git a/tests/unit-jq3.html b/tests/unit-jq3.html index e38105e3..4991d82b 100644 --- a/tests/unit-jq3.html +++ b/tests/unit-jq3.html @@ -94,6 +94,7 @@ + diff --git a/tests/utils/data-tests.js b/tests/utils/data-tests.js new file mode 100644 index 00000000..b557fe09 --- /dev/null +++ b/tests/utils/data-tests.js @@ -0,0 +1,36 @@ +module('Utils - RemoveData'); + +var $ = require('jquery'); +var Utils = require('select2/utils'); + +test('The data-select2-id attribute is removed', function (assert) { + var $element = $(''); + + Utils.RemoveData($element[0]); + + assert.notEqual( + $element.attr('data-select2-id'), + 'test', + 'The internal attribute was not removed when the data was cleared' + ); +}); + +test('The internal cache for the element is cleared', function (assert) { + var $element = $(''); + + Utils.__cache.test = { + 'foo': 'bar' + }; + + Utils.RemoveData($element[0]); + + assert.equal(Utils.__cache.test, null, 'The cache should now be empty'); +}); + +test('Calling it on an element without data works', function (assert) { + assert.expect(0); + + var $element = $(''); + + Utils.RemoveData($element[0]); +}); \ No newline at end of file