Module: PicoPhone::Rails::FormBuilderExtension

Defined in:
lib/pico_phone/rails/form_helper.rb

Overview

Included into ActionView::Helpers::FormBuilder by the railtie once ActionView loads. Adds f.pico_phone_field, mirroring PicoPhone::Rails::FormHelper#pico_phone_field_tag but bound to the form's object.

Examples:

f.pico_phone_field :phone, region: "US"
f.pico_phone_field :phone, region: ->(contact) { contact.organization.region }

Instance Method Summary collapse

Instance Method Details

#pico_phone_field(method, region: nil, **options) ⇒ String

Returns an HTML-safe <input type="tel"> tag.

Parameters:

  • method (Symbol)

    the attribute to render

  • region (String, Symbol, Proc, nil) (defaults to: nil)

    ISO 3166-1 alpha-2 region for interpreting the attribute's raw value when it isn't already a PhoneNumber -- a String is used as-is, a Symbol is called as an instance method on the form's object, a Proc is called with the object, same resolution rules as Extraction.extract_phone_numbers_from and PhoneSearchIndex.maintain_phone_search_index

Returns:

  • (String)

    an HTML-safe <input type="tel"> tag



63
64
65
66
67
# File 'lib/pico_phone/rails/form_helper.rb', line 63

def pico_phone_field(method, region: nil, **options)
  resolved_region = PicoPhone::Rails.resolve_region(region, object)
  display_value = PicoPhone::Rails.phone_field_display_value(object.public_send(method), resolved_region)
  text_field(method, options.merge(value: display_value, type: "tel"))
end