Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select2 now clears the internal ID when it is destroyed #5587

Merged
merged 1 commit into from Jul 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/js/select2/utils.js
Expand Up @@ -332,6 +332,8 @@ define([
if (Utils.__cache[id] != null) {
delete Utils.__cache[id];
}

element.removeAttribute('data-select2-id');
};

return Utils;
Expand Down
1 change: 1 addition & 0 deletions tests/unit-jq1.html
Expand Up @@ -94,6 +94,7 @@
<script src="selection/single-tests.js" type="text/javascript"></script>
<script src="selection/stopPropagation-tests.js" type="text/javascript"></script>

<script src="utils/data-tests.js" type="text/javascript"></script>
<script src="utils/decorator-tests.js" type="text/javascript"></script>
<script src="utils/escapeMarkup-tests.js" type="text/javascript"></script>
</body>
Expand Down
1 change: 1 addition & 0 deletions tests/unit-jq2.html
Expand Up @@ -94,6 +94,7 @@
<script src="selection/single-tests.js" type="text/javascript"></script>
<script src="selection/stopPropagation-tests.js" type="text/javascript"></script>

<script src="utils/data-tests.js" type="text/javascript"></script>
<script src="utils/decorator-tests.js" type="text/javascript"></script>
<script src="utils/escapeMarkup-tests.js" type="text/javascript"></script>
</body>
Expand Down
1 change: 1 addition & 0 deletions tests/unit-jq3.html
Expand Up @@ -94,6 +94,7 @@
<script src="selection/single-tests.js" type="text/javascript"></script>
<script src="selection/stopPropagation-tests.js" type="text/javascript"></script>

<script src="utils/data-tests.js" type="text/javascript"></script>
<script src="utils/decorator-tests.js" type="text/javascript"></script>
<script src="utils/escapeMarkup-tests.js" type="text/javascript"></script>
</body>
Expand Down
36 changes: 36 additions & 0 deletions 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 = $('<select data-select2-id="test"></select>');

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 = $('<select data-select2-id="test"></select>');

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 = $('<select></select>');

Utils.RemoveData($element[0]);
});