From 6a44ca350d8663dc7213039caf73acb2eef2622b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 28 Jun 2021 23:24:13 +0200 Subject: [PATCH] Render the advanced search form without JavaScript We were using the form and then showing it with JavaScript when advanced search terms were present. Now we hide it with JavaScript when no advanced search are present. This means users without JavaScript (including users with JavaScript enabled but bad internet connections preventing the JavaScript to load) can now access the form. The other main difference between the two versions is the way the form flashes while JavaScript is loading. Previously, the form would always be hidden when no terms had been introduced. However, when these terms were present, after submitting the form it would briefly be hidden and then shown again. Now the opposite happens. When advanced search terms are present, the form is shown at all times. However, when they aren't, the form is briefly shown before it disappears. Here the previous behavior is arguably better because most of the time these terms will not be present. So basically we're significantly improving the experience of some users at the cost of slightly worsen the experience of other users. We're also hiding the button to show the form when JavaScript is disabled, since in this scenario it's useless. We're using the `hidden` attribute so hidden buttons can be detected in CSS. --- app/assets/javascripts/advanced_search.js | 9 +++++++-- .../shared/advanced_search_component.html.erb | 4 ++-- .../shared/advanced_search_component_spec.rb | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/advanced_search.js b/app/assets/javascripts/advanced_search.js index 7ca0245a1..89f8be04f 100644 --- a/app/assets/javascripts/advanced_search.js +++ b/app/assets/javascripts/advanced_search.js @@ -14,11 +14,16 @@ } }, initialize: function() { + var toggle_button = $("#js-advanced-search-title"); + + toggle_button.removeAttr("hidden"); + if (App.AdvancedSearch.advanced_search_terms()) { - $("#js-advanced-search").show(); App.AdvancedSearch.toggle_date_options(); + } else { + $("#js-advanced-search").hide(); } - $("#js-advanced-search-title").on({ + toggle_button.on({ click: function() { $(this).attr("aria-expanded", !JSON.parse($(this).attr("aria-expanded"))); $("#js-advanced-search").slideToggle(); diff --git a/app/components/shared/advanced_search_component.html.erb b/app/components/shared/advanced_search_component.html.erb index 04926b755..f221eed99 100644 --- a/app/components/shared/advanced_search_component.html.erb +++ b/app/components/shared/advanced_search_component.html.erb @@ -1,11 +1,11 @@
-
<%= form_tag request.path, id: "advanced_search_form", class: "advanced-search-form", method: :get do %> -