1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-02 17:06:09 +00:00
webvirtcloud/static/js/searchable_select.js
catborise bc1894e4d8 fix(tags): at most 12 characters; "…" does not move the columns
- A new or renamed tag has at most 12 characters (computes.models.TAG_LENGTH,
  a validator: the column keeps 32, so names made before the limit stay
  usable until renamed and the migration changes no SQL); the tag box
  offers no longer name.
- The tags "…" shows in a table's cell go below the others within the
  cell's width as it is, so the list's columns no longer move.
2026-11-19 09:34:07 +03:00

30 lines
1.3 KiB
JavaScript

// A <select data-searchable> of many users or VMs gets a search box (Tom Select).
document.querySelectorAll("select[data-searchable]").forEach(function (select) {
new TomSelect(select, {
// the box leaves its focused, taller look at once: else the next tap's
// button moves away under the finger on a phone
onItemAdd: function () { this.blur(); },
});
});
// 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).
document.querySelectorAll("select[data-tags]").forEach(function (select) {
new TomSelect(select, {
create: function (input) {
return {value: input.toLowerCase(), text: input.toLowerCase()};
},
createFilter: function (input) {
return /^[A-Za-z0-9][A-Za-z0-9._-]{0,11}$/.test(input) && !this.options[input.toLowerCase()];
},
persist: false,
render: {
// the page's own words (data-add): 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>";
},
no_results: null,
},
});
});