Module: Bh::FormBuilder::Controls

Included in:
Bh::FormBuilder
Defined in:
lib/bh/form_builder/controls.rb

Overview

Every other kind of field, at the one size this builder draws them: a page says which kind it wants and nothing about how it looks. Rails hands an undressed control to whatever it has no method for here, which is how a Bootstrap class ends up written in a view.

Constant Summary collapse

CHECK =

What a box that is ticked wears, and what a circle does.

'check'
RADIO =
'radio'

Instance Method Summary collapse

Instance Method Details

#check(method, text, options = {}) ⇒ Object

A box and the words beside it, which is the one place words sit after a control rather than over it -- so they are not the label a field wears, and are written here instead. A description: is the line under those words, for a box whose label is too short to say what ticking it means. Every other option is the box's.



63
64
65
66
67
68
# File 'lib/bh/form_builder/controls.rb', line 63

def check(method, text, options = {})
  box = check_box method, options.except(:description)
  inside = @template.safe_join [box, checked_words(method, text, options[:description])]

  @template.tag.div inside, class: 'form-field'
end

#check_box(method, options = {}, checked = '1', unchecked = '0') ⇒ Object

One of several, ticked.



50
51
52
# File 'lib/bh/form_builder/controls.rb', line 50

def check_box(method, options = {}, checked = '1', unchecked = '0')
  super(method, with_classes(options, CHECK), checked, unchecked)
end

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

A day.



33
# File 'lib/bh/form_builder/controls.rb', line 33

def date_field(method, options = {}) = super(method, dressed(method, options))

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

A day and a time together.



39
# File 'lib/bh/form_builder/controls.rb', line 39

def datetime_field(method, options = {}) = super(method, dressed(method, options))

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

An email address, which a browser offers the one it keeps.



14
15
16
# File 'lib/bh/form_builder/controls.rb', line 14

def email_field(method, options = {})
  super(method, { autocomplete: 'email' }.merge(dressed(method, options)))
end

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

A number, which brings the keyboard for one.



19
# File 'lib/bh/form_builder/controls.rb', line 19

def number_field(method, options = {}) = super(method, dressed(method, options))

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

A password, which no name of a column earns on its own.



22
# File 'lib/bh/form_builder/controls.rb', line 22

def password_field(method, options = {}) = super(method, dressed(method, options))

#radio_button(method, value, options = {}) ⇒ Object

One of several, and only one.



55
56
57
# File 'lib/bh/form_builder/controls.rb', line 55

def radio_button(method, value, options = {})
  super(method, value, with_classes(options, RADIO))
end

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

A term to search by.



25
# File 'lib/bh/form_builder/controls.rb', line 25

def search_field(method, options = {}) = super(method, dressed(method, options))

#select(method, choices = nil, options = {}, html_options = {}) ⇒ Object

A menu of what a column may be.



45
46
47
# File 'lib/bh/form_builder/controls.rb', line 45

def select(method, choices = nil, options = {}, html_options = {}, &)
  super(method, choices, options, dressed(method, html_options), &)
end

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

More than a line of words.



42
# File 'lib/bh/form_builder/controls.rb', line 42

def text_area(method, options = {}) = super(method, dressed(method, options))

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

A time of day.



36
# File 'lib/bh/form_builder/controls.rb', line 36

def time_field(method, options = {}) = super(method, dressed(method, options))

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

A web address, which a browser offers the one it keeps.



28
29
30
# File 'lib/bh/form_builder/controls.rb', line 28

def url_field(method, options = {})
  super(method, { autocomplete: 'url' }.merge(dressed(method, options)))
end