Class: ActionForm::Subform
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- ActionForm::Subform
- Includes:
- ElementsDSL, Rendering, SchemaDSL
- Defined in:
- lib/action_form/subform.rb
Overview
Subform class for ActionForm that handles nested form structures. It allows building forms within forms, supporting has_one and has_many relationships. Includes schema and element DSL functionality for defining form elements.
Direct Known Subclasses
Class Attribute Summary collapse
-
.default ⇒ Object
Returns the value of attribute default.
Instance Attribute Summary collapse
-
#elements_instances ⇒ Object
readonly
Returns the value of attribute elements_instances.
-
#helpers ⇒ Object
Returns the value of attribute helpers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #build_from_object ⇒ Object
- #html_class ⇒ Object
- #html_id ⇒ Object
-
#initialize(name:, scope: nil, model: nil, params: nil, **tags) ⇒ Subform
constructor
A new instance of Subform.
- #render? ⇒ Boolean
- #template_html_id ⇒ Object
- #view_template ⇒ Object
Methods included from ElementsDSL
Methods included from SchemaDSL
Methods included from Rendering
#render_element, #render_elements, #render_form, #render_inline_errors, #render_input, #render_label, #render_many_subforms, #render_new_subform_button, #render_remove_subform_button, #render_subform, #render_submit
Constructor Details
#initialize(name:, scope: nil, model: nil, params: nil, **tags) ⇒ Subform
Returns a new instance of Subform.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/action_form/subform.rb', line 19 def initialize(name:, scope: nil, model: nil, params: nil, **) super() @name = name @scope = scope @object = model @params = params @elements_instances = [] @tags = build_from_object end |
Class Attribute Details
.default ⇒ Object
Returns the value of attribute default.
13 14 15 |
# File 'lib/action_form/subform.rb', line 13 def default @default end |
Instance Attribute Details
#elements_instances ⇒ Object (readonly)
Returns the value of attribute elements_instances.
16 17 18 |
# File 'lib/action_form/subform.rb', line 16 def elements_instances @elements_instances end |
#helpers ⇒ Object
Returns the value of attribute helpers.
17 18 19 |
# File 'lib/action_form/subform.rb', line 17 def helpers @helpers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/action_form/subform.rb', line 16 def name @name end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
16 17 18 |
# File 'lib/action_form/subform.rb', line 16 def object @object end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
16 17 18 |
# File 'lib/action_form/subform.rb', line 16 def @tags end |
Instance Method Details
#build_from_object ⇒ Object
30 31 32 33 34 35 |
# File 'lib/action_form/subform.rb', line 30 def build_from_object self.class.elements.each do |element_name, element_definition| @elements_instances << element_definition.new(element_name, @params || @object, parent_name: @scope) @elements_instances.last..merge!(subform: @name) end end |
#html_class ⇒ Object
49 50 51 |
# File 'lib/action_form/subform.rb', line 49 def html_class "#{name}_subform" end |
#html_id ⇒ Object
45 46 47 |
# File 'lib/action_form/subform.rb', line 45 def html_id "#{name}_#{[:index]}" end |
#render? ⇒ Boolean
37 38 39 |
# File 'lib/action_form/subform.rb', line 37 def render? true end |
#template_html_id ⇒ Object
41 42 43 |
# File 'lib/action_form/subform.rb', line 41 def template_html_id "#{name}_template" end |
#view_template ⇒ Object
53 54 55 |
# File 'lib/action_form/subform.rb', line 53 def view_template render_elements end |