Module: NdrUi::Bootstrap::InputGroupAddons

Included in:
NdrUi::BootstrapBuilder
Defined in:
app/builders/ndr_ui/bootstrap/input_group_addons.rb

Overview

Provides form builder method for Bootstrap input-group-addon

Instance Method Summary collapse

Instance Method Details

#text_field(method, options = {}) ⇒ Object

Identical signature to ActionView::Helpers::FormBuilder#text_field, but adds :prepend and :append options to prepend and append text to the text_field. Would typically be used for units (centigrays, mm, etc). This implementation adds the associated bootstrap styling to the add-ons.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/builders/ndr_ui/bootstrap/input_group_addons.rb', line 9

def text_field(method, options = {})
  options = options.stringify_keys
  prepend = options.delete('prepend')
  append = options.delete('append')

  return super if prepend.blank? && append.blank?
  div_content = []

  unless prepend.blank?
    div_content << @template.(:span, prepend, class: 'input-group-addon')
  end

  div_content << text_field_without_inline_errors(method, options)

  unless append.blank?
    div_content << @template.(:span, append, class: 'input-group-addon')
  end

  @template.(:div, @template.safe_join(div_content), class: 'input-group')
end