question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate tags when using remote data source

See original GitHub issue

I 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:

  1. Enter “tagabc” and press enter
  2. Enter “tagabc” again and select “tag1” from the dropdown
  3. 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
sgmckaycommented, Jan 5, 2017

I am experiencing the same issue and was able to reproduce in the fixed jsfiddle To reproduce:

  1. Enter “tag”
  2. Press enter (will have “tag” selected)
  3. Enter “tag”
  4. Select tag1

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.

2reactions
alexweissmancommented, Sep 15, 2017

Please refrain from “+1” comments. Simply click the 👍 button on the top comment to express your interest in this issue.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found