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-text

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
# 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 = []
  div_content << @template.(:span, prepend, class: 'input-group-text') if prepend.present?
  div_content << text_field_without_inline_errors(method, options)
  div_content << @template.(:span, append, class: 'input-group-text') if append.present?

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