Class: FormForms::Elements::Field

Inherits:
BaseElement show all
Defined in:
lib/form_forms/elements/field.rb

Overview

This represents a single form field. Typically this is the most low-level part of a form. You can either return a form element with the help of the passed form builder or just return arbitrary html. The block is executed in the scope of the view where the form is rendered. You can use any helpers defined there.

Note that you might need to mark your values as html_safe to avoid superfluous escaping in the view.

Example:

my_form = Form.new() do |form|
  form.field(:subject) {|f| f.input :subject}
  form.field(:link) do |f|
     :p do
      (:a, :href => hint_path){ "This is a hint" }
    end
  end
end

Direct Known Subclasses

TableHeaderField

Instance Attribute Summary

Attributes inherited from BaseElement

#elements

Instance Method Summary collapse

Methods inherited from BaseElement

#delete

Constructor Details

#initialize(&generator) ⇒ Field

Returns a new instance of Field.



23
24
25
# File 'lib/form_forms/elements/field.rb', line 23

def initialize(&generator)
  self.generator generator
end

Instance Method Details

#render(builder, view) ⇒ Object



29
30
31
# File 'lib/form_forms/elements/field.rb', line 29

def render(builder, view)
  eval_property(:generator, builder, view)
end