class ExpressTemplates::Components::Forms::FormComponent

Attributes

input_attributes[R]

Public Instance Methods

field_helper_options() click to toggle source
# File lib/express_templates/components/forms/form_component.rb, line 62
def field_helper_options
  {id: field_id_attribute}.merge(input_attributes||nil)
end
field_id_attribute() click to toggle source
# File lib/express_templates/components/forms/form_component.rb, line 58
def field_id_attribute
  "#{resource_name.singularize}_#{field_name}"
end
field_name() click to toggle source

Return the field_name as a string. This taken from the first argument to the component macro in the template or fragment.

# 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() click to toggle source

Return the field name attribute. Currently handles only simple attributes on the resource. Does not handle attributes for associated resources.

# File lib/express_templates/components/forms/form_component.rb, line 54
def field_name_attribute
  "#{resource_name.singularize}[#{field_name}]"
end
field_value() click to toggle source
# File lib/express_templates/components/forms/form_component.rb, line 48
def field_value
  resource.send(field_name)
end
label_name() click to toggle source

Return the name attribute for the label

# File lib/express_templates/components/forms/form_component.rb, line 33
def label_name
  field_helper_options[:id]
end
label_text() click to toggle source

Return the text content for the label

# File lib/express_templates/components/forms/form_component.rb, line 38
def label_text
  config[:label] || field_name.titleize
end
parent_form() click to toggle source

Search the parent graph until we find an ExpressForm. Returns nil if none found.

# 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() click to toggle source
# File lib/express_templates/components/forms/form_component.rb, line 18
def resource
  self.send(resource_name)
end
resource_class() click to toggle source
# File lib/express_templates/components/forms/form_component.rb, line 28
def resource_class
  parent_form.resource_class
end
resource_name() click to toggle source

Lookup the resource_name from the parent ExpressForm.

# 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

Protected Instance Methods

_process_builder_args!(args) click to toggle source

saving attributes for passing to the input field

Calls superclass method ExpressTemplates::Components::Capabilities::Configurable#_process_builder_args!
# File lib/express_templates/components/forms/form_component.rb, line 78
def _process_builder_args!(args)
  super(args)
  @input_attributes = args.last if args.last.kind_of?(Hash)
  @input_attributes ||= {}
  args.clear
end