Browse Source

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".
merge-requests/102/head
Deimos 5 years ago
parent
commit
c8f8697767
  1. 13
      tildes/static/js/behaviors/autocomplete-chip-clear.js

13
tildes/static/js/behaviors/autocomplete-chip-clear.js

@ -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();
}

Loading…
Cancel
Save