Skip to content

Commit

Permalink
Merge pull request #160 from twang817/fix_148
Browse files Browse the repository at this point in the history
fix select2-4.js to prevent duplicate options
  • Loading branch information
radiac authored Aug 13, 2024
2 parents 990b15a + 47799db commit a8ca492
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tagulous/static/tagulous/adaptor/select2-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
quotedTags: true,
allowClear: !options.required,
maximumSelectionLength: isSingle ? null : options.max_count || null,
spaceDelimiter: options.space_delimiter !== false
spaceDelimiter: options.space_delimiter !== false,
placeholder: options.placeholder || '',
});

// Add in any specific to the field type
Expand Down Expand Up @@ -252,6 +253,7 @@
var $selectCtl = $selectEl.select2(args);

if (selectedTags.length > 0) {
if (url) {
var selectedData = [];
for (var i=0; i<selectedTags.length; i++) {
var option = new Option(selectedTags[i], selectedTags[0], true, true);
Expand All @@ -265,6 +267,10 @@
data: selectedData,
}
});
} else {
$selectCtl.val(selectedTags);
$selectCtl.trigger("change");
}
}

// Ensure select2 data makes it back into the form field for submission
Expand Down

0 comments on commit a8ca492

Please sign in to comment.