Browse Source

Tags: Add client-side check for invalid characters

merge-requests/75/head
deing 5 years ago
committed by Deimos
parent
commit
d61511fde5
  1. 17
      tildes/scss/themes/_theme_base.scss
  2. 8
      tildes/static/js/behaviors/autocomplete-input.js
  3. 1
      tildes/tildes/templates/macros/forms.jinja2

17
tildes/scss/themes/_theme_base.scss

@ -230,6 +230,23 @@
color: $active-color; color: $active-color;
} }
} }
&.error {
background-color: map-get($theme, "error");
$error-color: #fff;
$is-error-bg-light: perceived-brightness(map-get($theme, "error")) > 50;
@if ($is-error-bg-light) {
$error-color: #000;
}
color: $error-color;
.btn {
color: $error-color;
}
}
} }
.comment-branch-counter { .comment-branch-counter {

8
tildes/static/js/behaviors/autocomplete-input.js

@ -35,6 +35,14 @@ $.onmount("[data-js-autocomplete-input]", function() {
$chip.html(tag); $chip.html(tag);
$chip.append(clearIcon); $chip.append(clearIcon);
if (!tag.match(/^[\w .]+$/)) {
$chip.addClass("error");
$chip.attr(
"title",
"Tags may only contain letters, numbers, and spaces."
);
}
$chips.append($chip); $chips.append($chip);
$tagsHiddenInput.val($tagsHiddenInput.val() + tag + ","); $tagsHiddenInput.val($tagsHiddenInput.val() + tag + ",");

1
tildes/tildes/templates/macros/forms.jinja2

@ -49,6 +49,7 @@
autocapitalize="none" autocapitalize="none"
spellcheck="false" spellcheck="false"
name="tags" name="tags"
pattern="[\w .,]*"
placeholder='Tags (like "music, soundtrack, full album")' placeholder='Tags (like "music, soundtrack, full album")'
data-js-autocomplete-input='{{ autocomplete_options|tojson if autocomplete_options }}' data-js-autocomplete-input='{{ autocomplete_options|tojson if autocomplete_options }}'
{% if value %} value="{{ value }}"{% endif %} {% if value %} value="{{ value }}"{% endif %}

Loading…
Cancel
Save