Class: SdrViewComponents::TabForm::TabbedFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Defined in:
app/components/sdr_view_components/tab_form/tabbed_form_builder.rb

Overview

A FormBuilder for use with SdrViewComponents::TabForm::TabListComponent-based forms.

TabListComponent doesn't render a

tag itself -- the real is rendered separately by the caller (see HiddenFieldsFormComponent), and fields are associated with it via the HTML form attribute rather than DOM nesting (since panes aren't necessarily inside the ). This builder automatically sets that form attribute on every field it builds, so callers don't need to pass form: form_id explicitly at every call site.

It also makes id (used above to derive the form attribute) available on builders created via fields_for, by falling back to the parent builder's id. Rails' fields_for doesn't otherwise propagate the html: { id: } option to nested builders.

Constant Summary collapse

FIELD_METHODS =
%i[text_field email_field textarea text_area hidden_field file_field radio_button checkbox
date_field].freeze

Instance Method Summary collapse

Instance Method Details

#idObject



36
37
38
# File 'app/components/sdr_view_components/tab_form/tabbed_form_builder.rb', line 36

def id
  super || options[:parent_builder]&.id
end

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



31
32
33
34
# File 'app/components/sdr_view_components/tab_form/tabbed_form_builder.rb', line 31

def select(method, choices = nil, options = {}, html_options = {}, &)
  html_options[:form] ||= id
  super
end