Class: Ui::Form::Builder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Ui::Form::Builder
- Includes:
- BuilderMixin
- Defined in:
- lib/uikit_rails/templates/components/form/builder.rb
Overview
Form builder that renders Ui::Input, Ui::Textarea, Ui::Select, Ui::Checkbox, Ui::Label, and Ui::Button via render_in so forms match standalone components.
Constant Summary collapse
- TEXT_FIELD_HELPERS =
{ text_field: "text", email_field: "email", password_field: "password", number_field: "number", phone_field: "tel", url_field: "url", search_field: "search", date_field: "date", time_field: "time", datetime_local_field: "datetime-local", month_field: "month", week_field: "week", color_field: "color" }.freeze
Instance Method Summary collapse
- #check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
-
#field(attribute, as: :text_field, label: nil, description: nil, **options) ⇒ Object
Renders label, control, optional description, and model errors.
- #label(attribute, text = nil, options = {}, &block) ⇒ Object
- #select(attribute, choices = nil, options = {}, html_options = {}) ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #text_area(attribute, options = {}) ⇒ Object
Instance Method Details
#check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
47 48 49 50 |
# File 'lib/uikit_rails/templates/components/form/builder.rb', line 47 def check_box(attribute, = {}, checked_value = "1", unchecked_value = "0") hidden, comp = checkbox_parts(attribute, , checked_value, unchecked_value) hidden + render_component_instance(comp) end |
#field(attribute, as: :text_field, label: nil, description: nil, **options) ⇒ Object
Renders label, control, optional description, and model errors.
57 58 59 60 61 |
# File 'lib/uikit_rails/templates/components/form/builder.rb', line 57 def field(attribute, as: :text_field, label: nil, description: nil, **) label_text = label || attribute.to_s.humanize inner = field_markup(attribute, as, label_text, description, ) @template.content_tag(:div, inner, class: "ui-form-field") end |
#label(attribute, text = nil, options = {}, &block) ⇒ Object
43 44 45 |
# File 'lib/uikit_rails/templates/components/form/builder.rb', line 43 def label(attribute, text = nil, = {}, &block) render_component_instance(build_ui_label(attribute, text, , block)) end |
#select(attribute, choices = nil, options = {}, html_options = {}) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/uikit_rails/templates/components/form/builder.rb', line 36 def select(attribute, choices = nil, = {}, = {}, &) return super if block_given? return super if choices.is_a?(Hash) render_component_instance(build_ui_select(attribute, choices, , )) end |
#submit(value = nil, options = {}) ⇒ Object
52 53 54 |
# File 'lib/uikit_rails/templates/components/form/builder.rb', line 52 def submit(value = nil, = {}) render_component_instance(build_submit_component(value, )) end |
#text_area(attribute, options = {}) ⇒ Object
32 33 34 |
# File 'lib/uikit_rails/templates/components/form/builder.rb', line 32 def text_area(attribute, = {}) render_component_instance(render_text_area_component(attribute, )) end |