Class: Aurita::GUI::Form_Field_Wrapper
- Defined in:
- lib/aurita-gui/form.rb
Overview
Default decorator for form fields. Decorates single entry of form to <li> element, setting CSS classes and DOM ids. To use your own field decorator, derive it from Aurita::GUI::Element (maybe indirectly via one of its derivates) and define its constructor to expect a single Form_Field instance. The field decorator has to wrap the actual form field.
See the source code of Aurita::GUI::Form_Field_Wrapper for a simple implementation.
Tell a form to use a specific field decorator by
the_form.field_decorator = My_Field_Decorator
To use your own implementation as defaut, overload Form.initialize like
class My_Form < Aurita::GUI::For
def initialize(params={}, &block)
super(params, &block)
@field_decorator = My_Field_Decorator
emd
end
Or write a factory (*hint hint*) like:
class Form_Factory
def self.form(params={}, &block)
form = Aurita::GUI::Form.new(params, &block)
form.field_decorator = My_Field_Decorator
return form
end
end
See also: Form_Content_Wrapper (pretty much the same).
Instance Attribute Summary collapse
-
#field ⇒ Object
Returns the value of attribute field.
Attributes inherited from Element
#attrib, #force_closing_tag, #gui_element_id, #parent, #tag
Instance Method Summary collapse
-
#initialize(field) ⇒ Form_Field_Wrapper
constructor
A new instance of Form_Field_Wrapper.
Methods inherited from Element
#+, #<<, #[], #[]=, #add_class, #aurita_gui_element, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #inspect, #js_init_code, #length, #method_missing, #recurse, #remove_class, #set_content, #string, #swap, #to_ary, #touch, #touched?, #type=, #untouch
Methods included from Marshal_Helper_Class_Methods
Methods included from Marshal_Helper
Constructor Details
#initialize(field) ⇒ Form_Field_Wrapper
Returns a new instance of Form_Field_Wrapper.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/aurita-gui/form.rb', line 67 def initialize(field) label_params = false if field.label then label_params = { :for => field.dom_id, :force_closing_tag => true } label_params[:id] = field.dom_id.to_s + '_label' if field.dom_id label = field.label @content = [ HTML.label(label_params) { label }, field ] else @content = field end field.dom_id = field.name.to_s.gsub('.','_') unless field.dom_id # Inherit css classes from decorated field, if any: css_classes = field.css_class.map { |c| c.to_s + '_wrap' if c } css_classes ||= [] css_classes << field.class.to_s.split('::')[-1].downcase + '_wrap form_field' css_classes << ' required' if field.required? css_classes << ' invalid' if field.invalid? params = { :tag => :li, :content => @content, :id => field.dom_id.to_s + '_wrap', :class => css_classes } super(params) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element
Instance Attribute Details
#field ⇒ Object
Returns the value of attribute field.
65 66 67 |
# File 'lib/aurita-gui/form.rb', line 65 def field @field end |