Duplicate tags when using remote data source
See original GitHub issueI am using Select2 to enable tagging. I need the user to be able to type in a tag and get back a list of results from an AJAX call. If the tag does not exist, the user should be able to create a tag. I’ve got most of the functionality working, but I ran into a strange issue where duplicate tags are created.
Steps to reproduce the issue
Using the example below or here, do the following:
- Enter “tagabc” and press enter
- Enter “tagabc” again and select “tag1” from the dropdown
- You should now see tag1, tagabc, and the duplicate tagabc in the list of tags.
Example
<html>
<head>
<style>
#tags {
width: 300px !important;
height: 100px !important;
position: relative !important;
display: block !important;
}
</style>
</head>
<body>
<h3>Steps to Reproduce</h3>
<ol>
<li>Enter "tagabc" and press enter</li>
<li>Enter "tagabc" again and select "tag1" from the dropdown</li>
</ol>
<p>You should now see tag1, tagabc, tagabc in the list of tags.</p>
<select id="tags" multiple style="width: 400px;"></select>
<script type="text/javascript">
$('#tags').select2({
tags: true,
ajax: {
url: 'https://api.myjson.com/bins/3oz54',
dataType: 'json',
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function(data, params) {
params.page = params.page || 1;
return {
results: data,
pagination: {
more: (params.page * 30) < data.total_count
}
};
}
}
});
</script>
</body>
</html>
Is this a bug or is there some filtering I should be doing that I’m not?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Duplicated tag on remote? - git - Stack Overflow
P.S.: I just tried deleting the tag on the remote ( git push origin :tagname ), it also deletes the one with ^{}...
Read more >Duplicate tag exists in file '' - Microsoft Dynamics AX Forum ...
These error occurs if you have a duplicate column name or due to the user defined column names and mainly due to blank...
Read more >dxTagBox doesn't work correctly for remote data source and ...
dxTagBox renders duplicate tags after search. dxTagBox doesn't work correctly for remote data source and valueExpr this.
Read more >Check Duplicate Tags Dialog - Bentley - Product Documentation
Enable this to check for duplicate tags on the copied component(s). If a duplicate is found, a message dialog displays prompting you to...
Read more >Browse a Data Source for New Tags Using Historian ...
Procedure · Open the Historian Non-Web Administrator. · Select the Collectors link from the toolbar. · If you have multiple collectors listed, select...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am experiencing the same issue and was able to reproduce in the fixed jsfiddle To reproduce:
Instead of selecting “tag1” it selects both “tag” and “tag1” so now it has “tag”, “tag”, “tag1” selected. If you search for “tag” again and select a different result it will again select “tag” and the result so now you have “tag” selected 3 times. Anytime you search for a term that has been selected (“tag”) and then select a result it selects both the result and the term causing the term to be duplicated in the selected options.
Please refrain from “+1” comments. Simply click the 👍 button on the top comment to express your interest in this issue.