Module: Decidim::Map::Autocomplete::FormBuilder

Included in:
FormBuilder
Defined in:
decidim-core/lib/decidim/map/autocomplete.rb

Overview

This module will be included in the main application’s form builder in order to provide the geocoding_field method for the normal form builders. This allows you to include geocoding autocompletion in the forms using the following code:

<%= form_for record do |form| %>
  <%= form.geocoding_field(:address) %>
<% end %>

Instance Method Summary collapse

Instance Method Details

#geocoding_field(attribute, options = {}, geocoding_options = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'decidim-core/lib/decidim/map/autocomplete.rb', line 41

def geocoding_field(attribute, options = {}, geocoding_options = {})
  @autocomplete_utility ||= Decidim::Map.autocomplete(
    organization: @template.current_organization
  )
  return text_field(attribute, options) unless @autocomplete_utility

  # Decidim::Map::Autocomplete::Builder
  builder = @autocomplete_utility.create_builder(
    @template,
    geocoding_options
  )

  options = merge_geocoding_options(attribute, options)

  field(attribute, options) do |opts|
    builder.geocoding_field(
      @object_name,
      attribute,
      opts
    )
  end
end