mirror of https://gitlab.com/tildes/tildes.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
// Copyright (c) 2019 Tildes contributors <code@tildes.net>
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
$.onmount("[data-js-autocomplete-chip-clear]", function () {
|
|
function clearChip($chip) {
|
|
var $tagsHiddenInput = $("[data-js-autocomplete-hidden-input]");
|
|
var $autocompleteInput = $("[data-js-autocomplete-input]");
|
|
|
|
var tags = $tagsHiddenInput.val().split(",");
|
|
var tagToRemove = $chip.text();
|
|
|
|
$tagsHiddenInput.val(
|
|
tags
|
|
.filter(function (tag) {
|
|
return tag !== tagToRemove;
|
|
})
|
|
.join(","),
|
|
);
|
|
|
|
$chip.remove();
|
|
$autocompleteInput.focus();
|
|
}
|
|
|
|
$(this).click(function (event) {
|
|
event.preventDefault();
|
|
clearChip($(this).parent());
|
|
});
|
|
|
|
$(this).keydown(function (event) {
|
|
switch (event.key) {
|
|
case "Backspace":
|
|
event.preventDefault();
|
|
clearChip($(this).parent());
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
});
|
|
});
|