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

'form-select form-select-lg'
CHECK =

What a box or a circle that is ticked wears.

'form-check-input'

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.



59
60
61
62
63
64
# File 'lib/bh/form_builder/controls.rb', line 59

def check(method, text, options = {})
  words = @template.label_tag field_id(method), text, class: 'form-check-label'
  inside = @template.safe_join [check_box(method, options), words]

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

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

One of several, ticked.



48
49
50
# File 'lib/bh/form_builder/controls.rb', line 48

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.



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

def date_field(method, options = {}) = super(method, with_classes(options, CONTROL))

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

A day and a time together.



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

def datetime_field(method, options = {}) = super(method, with_classes(options, CONTROL))

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

An email address.



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

def email_field(method, options = {}) = super(method, with_classes(options, CONTROL))

#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, with_classes(options, CONTROL))

#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, with_classes(options, CONTROL))

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

One of several, and only one.



53
54
55
# File 'lib/bh/form_builder/controls.rb', line 53

def radio_button(method, value, options = {})
  super(method, value, with_classes(options, CHECK))
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, with_classes(options, CONTROL))

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

A menu of what a column may be.



43
44
45
# File 'lib/bh/form_builder/controls.rb', line 43

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

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

More than a line of words.



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

def text_area(method, options = {}) = super(method, with_classes(options, CONTROL))

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

A time of day.



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

def time_field(method, options = {}) = super(method, with_classes(options, CONTROL))

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

A web address.



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

def url_field(method, options = {}) = super(method, with_classes(options, CONTROL))