From 5fe2fceb1d3a076a39c86abe6c92ef8def2fe122 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 22 Jul 2022 17:01:09 +0100 Subject: [PATCH] Filter out select an option value when javascript --- .../controllers/accessible_autocomplete_controller.js | 4 ++-- spec/features/user_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/frontend/controllers/accessible_autocomplete_controller.js b/app/frontend/controllers/accessible_autocomplete_controller.js index 242c0c3e4..3e19c4c9e 100644 --- a/app/frontend/controllers/accessible_autocomplete_controller.js +++ b/app/frontend/controllers/accessible_autocomplete_controller.js @@ -6,14 +6,14 @@ import { enhanceOption, suggestion, sort } from '../modules/search' export default class extends Controller { connect () { const selectEl = this.element - const selectOptions = Array.from(selectEl.options) + const selectOptions = Array.from(selectEl.options).filter(function (option, index, arr) { return option.value !== '' }) const options = selectOptions.map((o) => enhanceOption(o)) const matches = /^(\w+)\[(\w+)\]$/.exec(selectEl.name) const rawFieldName = matches ? `${matches[1]}[${matches[2]}_raw]` : '' accessibleAutocomplete.enhanceSelectElement({ - defaultValue: options[0].name, + defaultValue: '', selectElement: selectEl, minLength: 1, source: (query, populateResults) => { diff --git a/spec/features/user_spec.rb b/spec/features/user_spec.rb index 68caaec77..61f3ce024 100644 --- a/spec/features/user_spec.rb +++ b/spec/features/user_spec.rb @@ -630,7 +630,7 @@ RSpec.describe "User Features" do it "clears the previously selected organisation value" do visit("/logs") choose("organisation-select-specific-org-field", allow_label_click: true) - expect(page).to have_field("organisation-field", with: "Select an option") + expect(page).to have_field("organisation-field", with: "") find("#organisation-field").click.native.send_keys("F", "i", "l", "t", :down, :enter) click_button("Apply filters") expect(page).to have_current_path("/logs?%5Byears%5D%5B%5D=&%5Bstatus%5D%5B%5D=&user=all&organisation_select=specific_org&organisation=#{organisation.id}")