1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00

fix(tags): sixth audit: the tag box tells its rule, trims a paste; clear keeps the focus

- A name typed or pasted into the tag box that cannot be a tag shows the
  rule (letters a-z, digits, dots, dashes, underscores; at most 12
  characters) instead of nothing; the spaces a paste brings are dropped;
  "constructor" is no longer taken for a tag there is.
- "Clear the filters" hides with the message it is in: the search box takes
  the focus.
This commit is contained in:
catborise 2026-11-19 10:03:50 +03:00
parent bc1894e4d8
commit f6b1ee8985
9 changed files with 74 additions and 36 deletions

View file

@ -8,23 +8,32 @@ document.querySelectorAll("select[data-searchable]").forEach(function (select) {
});
// A <select multiple data-tags>: the tags there are, and a new one typed (the
// server checks it), in lower case as the tags are kept: "Prod" is "prod";
// a new one of at most 12 characters (computes.models.TAG_LENGTH).
// server checks it) of at most 12 characters (computes.models.TAG_LENGTH), as
// the tags are kept: without the spaces a paste brings, in lower case ("Prod"
// is "prod"). A name that cannot be a tag gets the rule (data-rule), not silence.
function tagName(input) {
return input.trim().toLowerCase();
}
function isTagName(input) {
return /^[a-z0-9][a-z0-9._-]{0,11}$/.test(tagName(input));
}
document.querySelectorAll("select[data-tags]").forEach(function (select) {
new TomSelect(select, {
create: function (input) {
return {value: input.toLowerCase(), text: input.toLowerCase()};
return {value: tagName(input), text: tagName(input)};
},
createFilter: function (input) {
return /^[A-Za-z0-9][A-Za-z0-9._-]{0,11}$/.test(input) && !this.options[input.toLowerCase()];
return isTagName(input) && !Object.hasOwn(this.options, tagName(input));
},
persist: false,
render: {
// the page's own words (data-add): the library's are English
// the page's own words (data-add, data-rule): the library's are English
option_create: function (data, escape) {
return '<div class="create">' + escape(select.dataset.add.replace("%(tag)s", data.input.toLowerCase())) + "</div>";
return '<div class="create">' + escape(select.dataset.add.replace("%(tag)s", tagName(data.input))) + "</div>";
},
no_results: function (data, escape) {
return isTagName(data.input) ? null : '<div class="no-results">' + escape(select.dataset.rule) + "</div>";
},
no_results: null,
},
});
});

View file

@ -189,6 +189,7 @@ if (typeof module !== "undefined") {
states.value = "";
}
filterTable(document);
search.focus(); // the button hid with the message it is in
});
}
filterTable(document);