Browse Source

Filter out select an option value when javascript

pull/778/head
baarkerlounger 3 years ago
parent
commit
5fe2fceb1d
  1. 4
      app/frontend/controllers/accessible_autocomplete_controller.js
  2. 2
      spec/features/user_spec.rb

4
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) => {

2
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}")

Loading…
Cancel
Save