From 1b0433055176ae5e87d42307799e3b977b13e225 Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 24 Apr 2019 23:04:21 -0600 Subject: [PATCH] Fix new topic tags no longer working without JS A user with JS disabled can submit new topics, but the autocomplete behavior was making it so that their tags were lost, because the "real" tags input was a hidden one that was only updated by JS. This starts the original (visible) input out as the tags one, and has the JS move it over to the hidden one, so it will only happen if they have JS enabled. --- tildes/static/js/behaviors/autocomplete-input.js | 7 +++++++ tildes/tildes/templates/macros/forms.jinja2 | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tildes/static/js/behaviors/autocomplete-input.js b/tildes/static/js/behaviors/autocomplete-input.js index 52981a1..5d6cca1 100644 --- a/tildes/static/js/behaviors/autocomplete-input.js +++ b/tildes/static/js/behaviors/autocomplete-input.js @@ -37,6 +37,13 @@ $.onmount('[data-js-autocomplete-input]', function() { $.onmount(); } + // initialization (won't repeat on re-mounts because it removes the name attr) + if ($(this).attr("name")) { + // move the "tags" name to the hidden input (so the form works without JS) + $(this).removeAttr("name"); + $("[data-js-autocomplete-hidden-input]").attr("name", "tags"); + } + if ($(this).val() !== '') { addChip($(this)); } diff --git a/tildes/tildes/templates/macros/forms.jinja2 b/tildes/tildes/templates/macros/forms.jinja2 index 5d4be73..2448bb6 100644 --- a/tildes/tildes/templates/macros/forms.jinja2 +++ b/tildes/tildes/templates/macros/forms.jinja2 @@ -32,7 +32,7 @@ autocomplete="off" autocapitalize="none" spellcheck="false" - name="query" + name="tags" placeholder='Tags (like "music, soundtrack, full album")' data-js-autocomplete-input='{{ autocomplete_options|tojson if autocomplete_options }}' {% if value %} value="{{ value }}"{% endif %} @@ -40,7 +40,7 @@ >
- + {% endmacro %}