From 1148614eff14253aadf670eb21a003c0305232b9 Mon Sep 17 00:00:00 2001 From: andrew nimmo Date: Sat, 17 Aug 2024 13:38:23 -0700 Subject: [PATCH] Fix application of autocompleter outlet ID --- app/helpers/autocompleter_helper.rb | 21 +++++++++++-------- app/helpers/forms_helper.rb | 2 +- .../observations/form/_details.html.erb | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/helpers/autocompleter_helper.rb b/app/helpers/autocompleter_helper.rb index 98c5e5e205..309c480701 100644 --- a/app/helpers/autocompleter_helper.rb +++ b/app/helpers/autocompleter_helper.rb @@ -21,13 +21,14 @@ def autocompleter_field(**args) data: { autocompleter_target: "input" } }.deep_merge(args.except(*autocompleter_outer_args)) ac_args[:class] = class_names("dropdown", args[:class]) - # doing our own wrap here, because dropdown is position-absolute - ac_args[:wrap_data] = { autocompleter_target: "wrap"} + # inner form-group wrap, because dropdown is position-absolute + ac_args[:wrap_data] = { autocompleter_target: "wrap" } ac_args[:label_after] = autocompleter_label_after(args) ac_args[:label_end] = autocompleter_label_end(args) ac_args[:append] = autocompleter_dropdown - tag.div(data: autocompleter_wrap_data(args)) do + tag.div(id: args[:controller_id], + data: autocompleter_controller_data(args)) do if args[:textarea] == true concat(text_area_with_label(**ac_args)) else @@ -39,18 +40,20 @@ def autocompleter_field(**args) # Any arg not on this list gets sent to the text field/area. def autocompleter_outer_args - [:wrap_data, :type, :separator, :textarea, :hidden_value, :hidden_data, - :create_text, :keep_text, :edit_text, :find_text, :create, :create_path, - :map_outlet, :geocode_outlet].freeze + [:controller_data, :controller_id, :type, :separator, :textarea, + :hidden_value, :hidden_data, :create_text, :keep_text, :edit_text, + :find_text, :create, :create_path, :map_outlet, :geocode_outlet].freeze end - def autocompleter_wrap_data(args) + # This data goes on the outer div (controller element), not the input field. + def autocompleter_controller_data(args) { - controller: :autocompleter, type: args[:type], + controller: :autocompleter, + type: args[:type], separator: args[:separator], autocompleter_map_outlet: args[:map_outlet], autocompleter_geocode_outlet: args[:geocode_outlet] - }.deep_merge(args[:wrap_data] || {}) + }.deep_merge(args[:outer_data] || {}) end def autocompleter_label_after(args) diff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rb index 2897affb36..a55be8171d 100644 --- a/app/helpers/forms_helper.rb +++ b/app/helpers/forms_helper.rb @@ -164,7 +164,7 @@ def text_field_with_label(**args) label_opts = field_label_opts(args) label_opts[:class] = class_names(label_opts[:class], args[:label_class]) - tag.div(class: wrap_class, data: wrap_data, id: args[:wrap_id]) do + tag.div(class: wrap_class, data: wrap_data) do concat(text_label_row(args, label_opts)) if args[:addon].present? # text addon, not interactive concat(tag.div(class: "input-group") do diff --git a/app/views/controllers/observations/form/_details.html.erb b/app/views/controllers/observations/form/_details.html.erb index eaac83ae5d..8d5733b808 100644 --- a/app/views/controllers/observations/form/_details.html.erb +++ b/app/views/controllers/observations/form/_details.html.erb @@ -45,7 +45,7 @@ t_s = { # find_text: :form_locations_find_on_map.l, # Be precise about which map controller to connect to: map_outlet: "#observation_form", - wrap_id: "observation_location_autocompleter", + controller_id: "observation_location_autocompleter", # Action ok because there's only one form-exif controller on the page, # and it should only affect this autocompleter: data: {