1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +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

@ -33,8 +33,10 @@ class TagsWidget(forms.SelectMultiple):
"""The tags there are and those given, to choose from or add to (Tom Select)."""
def __init__(self):
# Tom Select's line for a new name typed (searchable_select.js)
super().__init__(attrs={"data-tags": "", "data-add": _("Add tag %(tag)s")})
# Tom Select's line for a new name typed, and for one that cannot be a tag (searchable_select.js)
super().__init__(attrs={"data-tags": "", "data-add": _("Add tag %(tag)s"), "data-rule": _(
"A new tag: letters a-z, digits, dots, dashes and underscores, beginning with a letter or digit; "
"at most 12 characters")})
def optgroups(self, name, value, attrs=None):
self.choices = [(n, n) for n in sorted(set(Tag.objects.values_list("name", flat=True)) | set(value))]