Class: ExpressTemplates::Components::Forms::FormComponent
- Inherits:
-
Configurable
- Object
- Arbre::Component
- Base
- Configurable
- ExpressTemplates::Components::Forms::FormComponent
- Defined in:
- lib/express_templates/components/forms/form_component.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary collapse
-
#input_attributes ⇒ Object
readonly
Returns the value of attribute input_attributes.
Instance Method Summary collapse
- #field_helper_options ⇒ Object
- #field_id_attribute ⇒ Object
-
#field_name ⇒ Object
Return the field_name as a string.
-
#field_name_attribute ⇒ Object
Return the field name attribute.
- #field_value ⇒ Object
-
#label_name ⇒ Object
Return the name attribute for the label.
-
#label_text ⇒ Object
Return the text content for the label.
-
#parent_form ⇒ Object
Search the parent graph until we find an ExpressForm.
- #resource ⇒ Object
- #resource_class ⇒ Object
-
#resource_name ⇒ Object
Lookup the resource_name from the parent ExpressForm.
Methods included from Capabilities::Configurable
Methods inherited from Base
abstract_component, abstract_component?, before_build, #build, builder_method, builder_method_and_class, contains, descendants, has_attributes, inherited, #initialize, require_parent, required_parent, tag
Constructor Details
This class inherits a constructor from ExpressTemplates::Components::Base
Instance Attribute Details
#input_attributes ⇒ Object (readonly)
Returns the value of attribute input_attributes.
6 7 8 |
# File 'lib/express_templates/components/forms/form_component.rb', line 6 def input_attributes @input_attributes end |
Instance Method Details
#field_helper_options ⇒ Object
62 63 64 |
# File 'lib/express_templates/components/forms/form_component.rb', line 62 def {id: field_id_attribute}.merge(input_attributes||nil) end |
#field_id_attribute ⇒ Object
58 59 60 |
# File 'lib/express_templates/components/forms/form_component.rb', line 58 def field_id_attribute "#{resource_name.singularize}_#{field_name}" end |
#field_name ⇒ Object
Return the field_name as a string. This taken from the first argument to the component macro in the template or fragment.
44 45 46 |
# File 'lib/express_templates/components/forms/form_component.rb', line 44 def field_name (config[:id] || (@args.first.is_a?(String) && @args.first)).to_s end |
#field_name_attribute ⇒ Object
Return the field name attribute. Currently handles only simple attributes on the resource. Does not handle attributes for associated resources.
54 55 56 |
# File 'lib/express_templates/components/forms/form_component.rb', line 54 def field_name_attribute "#{resource_name.singularize}[#{field_name}]" end |
#field_value ⇒ Object
48 49 50 |
# File 'lib/express_templates/components/forms/form_component.rb', line 48 def field_value resource.send(field_name) end |
#label_name ⇒ Object
Return the name attribute for the label
33 34 35 |
# File 'lib/express_templates/components/forms/form_component.rb', line 33 def label_name [:id] end |
#label_text ⇒ Object
Return the text content for the label
38 39 40 |
# File 'lib/express_templates/components/forms/form_component.rb', line 38 def label_text config[:label] || field_name.titleize end |
#parent_form ⇒ Object
Search the parent graph until we find an ExpressForm. Returns nil if none found.
67 68 69 70 71 72 73 |
# File 'lib/express_templates/components/forms/form_component.rb', line 67 def parent_form @my_form ||= parent until @my_form.nil? || @my_form.kind_of?(ExpressForm) @my_form = @my_form.parent end return @my_form end |
#resource ⇒ Object
18 19 20 |
# File 'lib/express_templates/components/forms/form_component.rb', line 18 def resource self.send(resource_name) end |
#resource_class ⇒ Object
28 29 30 |
# File 'lib/express_templates/components/forms/form_component.rb', line 28 def resource_class parent_form.resource_class end |
#resource_name ⇒ Object
Lookup the resource_name from the parent ExpressForm.
23 24 25 26 |
# File 'lib/express_templates/components/forms/form_component.rb', line 23 def resource_name raise "FormComponent must have a parent form" unless parent_form parent_form.config[:id].to_s end |