From 60756adeaf6238bc7aee81a8c51b58e4681346a2 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 2 Jan 2024 10:00:39 +0000 Subject: [PATCH] CLDC-1753 Update accessible autocomplete (#2108) * Update accessible autocomplete * lint, remove test * Only get org if id is given --- app/controllers/form_controller.rb | 2 +- .../controllers/accessible_autocomplete_controller.js | 7 +++++++ app/views/form/_select_question.html.erb | 3 +-- spec/features/form/accessible_autocomplete_spec.rb | 4 ---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb index 9fb0fe243..2f6ce6483 100644 --- a/app/controllers/form_controller.rb +++ b/app/controllers/form_controller.rb @@ -103,7 +103,7 @@ private end if question.id == "owning_organisation_id" - owning_organisation = Organisation.find(result["owning_organisation_id"]) + owning_organisation = result["owning_organisation_id"].present? ? Organisation.find(result["owning_organisation_id"]) : nil if current_user.support? && @log.managing_organisation.blank? && owning_organisation&.managing_agents&.empty? result["managing_organisation_id"] = owning_organisation.id elsif owning_organisation&.absorbing_organisation == current_user.organisation diff --git a/app/frontend/controllers/accessible_autocomplete_controller.js b/app/frontend/controllers/accessible_autocomplete_controller.js index 3e19c4c9e..b510a6b02 100644 --- a/app/frontend/controllers/accessible_autocomplete_controller.js +++ b/app/frontend/controllers/accessible_autocomplete_controller.js @@ -32,5 +32,12 @@ export default class extends Controller { if (selectedOption) selectedOption.selected = true } }) + + const parentElement = selectEl.parentElement + const inputElement = parentElement.querySelector('[role=combobox]') + + inputElement.addEventListener('input', () => { + selectOptions.forEach((option) => { option.selected = false }) + }) } } diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index da44ba845..ca90a1e4e 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -13,8 +13,7 @@ data-synonyms="<%= answer_option_synonyms(answer.resource) %>" data-append="<%= answer_option_append(answer.resource) %>" data-hint="<%= answer_option_hint(answer.resource) %>" - <%= question.answer_selected?(@log, answer) ? "selected" : "" %> - <%= answer.id == "" ? "disabled" : "" %>><%= answer.name || answer.resource %> + <%= question.answer_selected?(@log, answer) ? "selected" : "" %>><%= answer.name || answer.resource %> <% end %> <% end %> diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb index 18f7c3411..255f95f83 100644 --- a/spec/features/form/accessible_autocomplete_spec.rb +++ b/spec/features/form/accessible_autocomplete_spec.rb @@ -63,10 +63,6 @@ RSpec.describe "Accessible Autocomplete" do click_link(text: "Back") expect(page).to have_selector("input", class: "autocomplete__input", count: 1) end - - it "has a disabled null option" do - expect(page).to have_select("lettings-log-prevloc-field", disabled_options: ["Select an option"]) - end end context "when searching schemes" do