mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-17 14:59:11 +02:00
Fix autocomplete chip X "ends with" conflicts
Let's try this again without the regex. Clicking the X button in an autocomplete chip could inadvertently remove the wrong tag (and cause a weird "merging" behavior) if another tag ended with the same text as the one being removed. For example, if a post had both "one.two" and "two" tags and you clicked the X button on the "two".
This commit is contained in:
@@ -6,8 +6,17 @@ $.onmount("[data-js-autocomplete-chip-clear]", function() {
|
||||
var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]");
|
||||
var $autocompleteInput = $("[data-js-autocomplete-input]");
|
||||
|
||||
var textToReplace = new RegExp($chip.text() + ",");
|
||||
$tagsHiddenInput.val($tagsHiddenInput.val().replace(textToReplace, ""));
|
||||
var tags = $tagsHiddenInput.val().split(",");
|
||||
var tagToRemove = $chip.text();
|
||||
|
||||
$tagsHiddenInput.val(
|
||||
tags
|
||||
.filter(function(tag) {
|
||||
return tag !== tagToRemove;
|
||||
})
|
||||
.join(",")
|
||||
);
|
||||
|
||||
$chip.remove();
|
||||
$autocompleteInput.focus();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user