Browse Source

Hide text search input when js is enabled

pull/2535/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
170e46e504
  1. 4
      app/frontend/controllers/search_controller.js
  2. 12
      app/helpers/filters_helper.rb
  3. 3
      app/views/filters/_select_filter.html.erb

4
app/frontend/controllers/search_controller.js

@ -25,6 +25,10 @@ export default class extends Controller {
const rawFieldName = matches ? `${matches[1]}[${matches[2]}_raw]` : ''
const searchUrl = JSON.parse(this.element.dataset.info).search_url
document.querySelectorAll('.non-js-text-search-input-field').forEach((el) => {
el.style.display = 'none'
})
accessibleAutocomplete.enhanceSelectElement({
defaultValue: '',
selectElement: selectEl,

12
app/helpers/filters_helper.rb

@ -102,13 +102,13 @@ module FiltersHelper
def assigned_to_filter_options(filter_type)
if applied_filters(filter_type)["assigned_to"] == "specific_user" && applied_filters(filter_type)["user"].present?
user_id = applied_filters(filter_type)["user"]
user = if user.support?
User.where(id: user_id)&.first
else
User.affiliated_users(user.organisation).where(id: user_id)&.first
end
selected_user = if current_user.support?
User.where(id: user_id)&.first
else
User.affiliated_users(current_user.organisation).where(id: user_id)&.first
end
return [OpenStruct.new(id: user.id, name: user.name, hint: user.email)] if user.present?
return [OpenStruct.new(id: selected_user.id, name: selected_user.name, hint: selected_user.email)] if selected_user.present?
end
[OpenStruct.new(id: "", name: "Select an option", hint: "")]
end

3
app/views/filters/_select_filter.html.erb

@ -1,10 +1,11 @@
<span class="non-js-text-search-input-field">
<%= f.govuk_text_field "#{category}_text_search".to_sym,
label: { text: label, hidden: secondary },
"data-controller": "search conditional-filter",
caption: { text: caption_text },
"data-info": { search_url: filter_search_url(category.to_sym) }.to_json,
value: selected_option("#{category}_text_search", @filter_type) %>
</span>
<%= f.govuk_select(category.to_sym,
label: { text: label, hidden: secondary },
"data-controller": "search conditional-filter",

Loading…
Cancel
Save