Module: Aurita::GUI::Form_Field_Helper
- Included in:
- Form
- Defined in:
- lib/aurita-gui/form/template_helper.rb
Overview
Provides wrapper methods for every form field type. Include this module in your template helper class.
Form_Helper methods each return a string for a respective Form_Field element. Rendering respects the form instances’ @field_decorator, but not @content_decorator, so you have to wrap form contents manually in your helper method.
Example: (what your template helper could look like)
module Form_Helper_Class_Methods
def form_for(params, &block)
form = Form.new(params, &block)
render form.header_string # <form ...> tag is prepared by form instance
render '<ul class="form_fields">' # begin content wrap
yield(form)
render '</ul>' # end content wrap
render '</form>' # Closing tag for a form should always be </form>
end
end
Usage, e.g. in ERB templates:
<% form_for(:action => '/where/to/send') do |f| %>
<%= f.text(:name => :title) { 'Value for this field' } %>
<%= f.select(:name => :color, :options => [ :blue, :red, :green ], :value => :red)
<% end %>
Form_Helper automatically extends Aurita::GUI::Form when included.
Instance Method Summary collapse
- #boolean(params, &block) ⇒ Object
- #checkbox(params, &block) ⇒ Object
- #custom(params, &block) ⇒ Object
- #date(params, &block) ⇒ Object
- #datetime(params, &block) ⇒ Object
- #fieldset(params, &block) ⇒ Object
- #file(params, &block) ⇒ Object
- #hidden(params, &block) ⇒ Object
- #password(params, &block) ⇒ Object
- #radio(params, &block) ⇒ Object
- #select(params, &block) ⇒ Object
- #text(params, &block) ⇒ Object
- #textarea(params, &block) ⇒ Object
Instance Method Details
#boolean(params, &block) ⇒ Object
49 50 51 |
# File 'lib/aurita-gui/form/template_helper.rb', line 49 def boolean(params, &block) @field_decorator.new(Boolean_Field.new(params, &block)).string end |
#checkbox(params, &block) ⇒ Object
66 67 68 |
# File 'lib/aurita-gui/form/template_helper.rb', line 66 def checkbox(params, &block) @field_decorator.new(Checkbox_Field.new(params, &block)).string end |
#custom(params, &block) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/aurita-gui/form/template_helper.rb', line 94 def custom(params, &block) if params.is_a?(Element) then element = params else klass = params[:element] params.delete(:element) element = klass.new(params, &block) end @field_decorator.new(element).string end |
#date(params, &block) ⇒ Object
86 87 88 |
# File 'lib/aurita-gui/form/template_helper.rb', line 86 def date(params, &block) @field_decorator.new(Date_Field.new(params, &block)).string end |
#datetime(params, &block) ⇒ Object
90 91 92 |
# File 'lib/aurita-gui/form/template_helper.rb', line 90 def datetime(params, &block) @field_decorator.new(Datetime_Field.new(params, &block)).string end |
#fieldset(params, &block) ⇒ Object
82 83 84 |
# File 'lib/aurita-gui/form/template_helper.rb', line 82 def fieldset(params, &block) @field_decorator.new(Fieldset.new(params, &block)).string end |
#file(params, &block) ⇒ Object
78 79 80 |
# File 'lib/aurita-gui/form/template_helper.rb', line 78 def file(params, &block) @field_decorator.new(File_Field.new(params, &block)).string end |
#hidden(params, &block) ⇒ Object
74 75 76 |
# File 'lib/aurita-gui/form/template_helper.rb', line 74 def hidden(params, &block) @field_decorator.new(Hidden_Field.new(params, &block)).string end |
#password(params, &block) ⇒ Object
53 54 55 56 |
# File 'lib/aurita-gui/form/template_helper.rb', line 53 def password(params, &block) params[:type] = :password @field_decorator.new(Password_Field.new(params, &block)).string end |
#radio(params, &block) ⇒ Object
62 63 64 |
# File 'lib/aurita-gui/form/template_helper.rb', line 62 def radio(params, &block) @field_decorator.new(Radio_Field.new(params, &block)).string end |
#select(params, &block) ⇒ Object
58 59 60 |
# File 'lib/aurita-gui/form/template_helper.rb', line 58 def select(params, &block) @field_decorator.new(Select_Field.new(params, &block)).string end |
#text(params, &block) ⇒ Object
44 45 46 47 |
# File 'lib/aurita-gui/form/template_helper.rb', line 44 def text(params, &block) params[:type] = :text @field_decorator.new(Input_Field.new(params, &block)).string end |
#textarea(params, &block) ⇒ Object
70 71 72 |
# File 'lib/aurita-gui/form/template_helper.rb', line 70 def textarea(params, &block) @field_decorator.new(Textarea_Field.new(params, &block)).string end |