Class: BetterUi::UiFormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BetterUi::UiFormBuilder
- Defined in:
- app/form_builders/better_ui/ui_form_builder.rb
Overview
Custom Rails form builder for rendering form inputs using BetterUi::Forms components.
This form builder integrates seamlessly with ActiveModel objects to automatically populate field values, validation errors, and required status from the model. All form inputs are rendered using ViewComponents from the BetterUi::Forms namespace, ensuring consistent styling and behavior across the application.
Instance Method Summary collapse
-
#bui_checkbox(attribute, options = {}) ⇒ String
Renders a checkbox input field using BetterUi::Forms::CheckboxComponent.
-
#bui_checkbox_group(attribute, collection, options = {}) ⇒ String
Renders a checkbox group using BetterUi::Forms::CheckboxGroupComponent.
-
#bui_date_input(attribute, options = {}, &block) ⇒ String
Renders a date input field using BetterUi::Forms::TextInputComponent with type: :date.
-
#bui_email_input(attribute, options = {}, &block) ⇒ String
Renders an email input field using BetterUi::Forms::TextInputComponent with type: :email.
-
#bui_number_input(attribute, options = {}, &block) ⇒ String
Renders a number input field using BetterUi::Forms::NumberInputComponent.
-
#bui_password_input(attribute, options = {}, &block) ⇒ String
Renders a password input field using BetterUi::Forms::PasswordInputComponent.
-
#bui_select(attribute, collection, options = {}, &block) ⇒ String
Renders a custom select dropdown using BetterUi::Forms::SelectComponent.
-
#bui_tel_input(attribute, options = {}, &block) ⇒ String
Renders a telephone input field using BetterUi::Forms::TextInputComponent with type: :tel.
-
#bui_text_input(attribute, options = {}, &block) ⇒ String
Renders a text input field using BetterUi::Forms::TextInputComponent.
-
#bui_textarea(attribute, options = {}, &block) ⇒ String
Renders a textarea field using BetterUi::Forms::TextareaComponent.
-
#bui_time_input(attribute, options = {}, &block) ⇒ String
Renders a time input field using BetterUi::Forms::TextInputComponent with type: :time.
Instance Method Details
#bui_checkbox(attribute, options = {}) ⇒ String
Renders a checkbox input field using BetterUi::Forms::CheckboxComponent
285 286 287 288 289 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 285 def bui_checkbox(attribute, = {}) = (attribute, ) @template.render(BetterUi::Forms::CheckboxComponent.new(**)) end |
#bui_checkbox_group(attribute, collection, options = {}) ⇒ String
Renders a checkbox group using BetterUi::Forms::CheckboxGroupComponent
315 316 317 318 319 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 315 def bui_checkbox_group(attribute, collection, = {}) = (attribute, collection, ) @template.render(BetterUi::Forms::CheckboxGroupComponent.new(**)) end |
#bui_date_input(attribute, options = {}, &block) ⇒ String
Renders a date input field using BetterUi::Forms::TextInputComponent with type: :date
116 117 118 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 116 def bui_date_input(attribute, = {}, &block) bui_text_input(attribute, .merge(type: :date), &block) end |
#bui_email_input(attribute, options = {}, &block) ⇒ String
Renders an email input field using BetterUi::Forms::TextInputComponent with type: :email
92 93 94 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 92 def bui_email_input(attribute, = {}, &block) bui_text_input(attribute, .merge(type: :email), &block) end |
#bui_number_input(attribute, options = {}, &block) ⇒ String
Renders a number input field using BetterUi::Forms::NumberInputComponent
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 162 def bui_number_input(attribute, = {}, &block) = (attribute, ) # Add number-specific options [:min] = [:min] if .key?(:min) [:max] = [:max] if .key?(:max) [:step] = [:step] if .key?(:step) [:show_spinner] = .fetch(:show_spinner, true) if block_given? @template.render(BetterUi::Forms::NumberInputComponent.new(**), &block) else @template.render(BetterUi::Forms::NumberInputComponent.new(**)) end end |
#bui_password_input(attribute, options = {}, &block) ⇒ String
Renders a password input field using BetterUi::Forms::PasswordInputComponent
204 205 206 207 208 209 210 211 212 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 204 def bui_password_input(attribute, = {}, &block) = (attribute, ) if block_given? @template.render(BetterUi::Forms::PasswordInputComponent.new(**), &block) else @template.render(BetterUi::Forms::PasswordInputComponent.new(**)) end end |
#bui_select(attribute, collection, options = {}, &block) ⇒ String
Renders a custom select dropdown using BetterUi::Forms::SelectComponent
349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 349 def bui_select(attribute, collection, = {}, &block) = (attribute, ) [:collection] = collection [:clearable] = .fetch(:clearable, false) [:dropdown_classes] = [:dropdown_classes] if .key?(:dropdown_classes) if block_given? @template.render(BetterUi::Forms::SelectComponent.new(**), &block) else @template.render(BetterUi::Forms::SelectComponent.new(**)) end end |
#bui_tel_input(attribute, options = {}, &block) ⇒ String
Renders a telephone input field using BetterUi::Forms::TextInputComponent with type: :tel
104 105 106 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 104 def bui_tel_input(attribute, = {}, &block) bui_text_input(attribute, .merge(type: :tel), &block) end |
#bui_text_input(attribute, options = {}, &block) ⇒ String
Renders a text input field using BetterUi::Forms::TextInputComponent
73 74 75 76 77 78 79 80 81 82 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 73 def bui_text_input(attribute, = {}, &block) = (attribute, ) [:type] = [:type] if .key?(:type) if block_given? @template.render(BetterUi::Forms::TextInputComponent.new(**), &block) else @template.render(BetterUi::Forms::TextInputComponent.new(**)) end end |
#bui_textarea(attribute, options = {}, &block) ⇒ String
Renders a textarea field using BetterUi::Forms::TextareaComponent
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 246 def bui_textarea(attribute, = {}, &block) = (attribute, ) # Add textarea-specific options [:rows] = .fetch(:rows, 4) [:cols] = [:cols] if .key?(:cols) [:maxlength] = [:maxlength] if .key?(:maxlength) [:resize] = .fetch(:resize, :vertical) if block_given? @template.render(BetterUi::Forms::TextareaComponent.new(**), &block) else @template.render(BetterUi::Forms::TextareaComponent.new(**)) end end |
#bui_time_input(attribute, options = {}, &block) ⇒ String
Renders a time input field using BetterUi::Forms::TextInputComponent with type: :time
128 129 130 |
# File 'app/form_builders/better_ui/ui_form_builder.rb', line 128 def bui_time_input(attribute, = {}, &block) bui_text_input(attribute, .merge(type: :time), &block) end |