Skip to content

Commit

Permalink
Fix application of autocompleter outlet ID
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 17, 2024
1 parent b112cc3 commit 1148614
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions app/helpers/autocompleter_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/controllers/observations/form/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 1148614

Please sign in to comment.