Class: Aurita::GUI::Form_Field
- Defined in:
- lib/aurita-gui/form/form_field.rb
Overview
Class Form_Field is an abstract base class for built-in form fields (Input_Field, Hidden_Field, Radio_Field, Checkbox_Field, Select_Field, Textarea_Field) or any custom form field type. It is a wrapper for GUI::Element, extending it by parameters @name, @label and @value.
Usage:
i = Input_Field.new(:name => :description,
:label => 'Description',
:value => 'Lorem ipsum dolor')
Apart from this special attributes, Form_Field instances behave like any GUI::Element:
i.onclick = "alert('i have been clicked');"
i.class = 'css_class'
Direct Known Subclasses
Date_Field, File_Field, Hidden_Field, Input_Field, Options_Field, Textarea_Field
Instance Attribute Summary collapse
-
#form ⇒ Object
Returns the value of attribute form.
-
#label ⇒ Object
Returns the value of attribute label.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Attributes inherited from Element
#attrib, #content, #parent, #tag
Instance Method Summary collapse
- #disable! ⇒ Object
- #editable! ⇒ Object
- #element ⇒ Object
- #enable! ⇒ Object
-
#initialize(params) ⇒ Form_Field
constructor
A new instance of Form_Field.
- #readonly! ⇒ Object
- #readonly? ⇒ Boolean
- #readonly_element ⇒ Object
- #to_s ⇒ Object (also: #string)
Methods inherited from Element
#+, #[], #[]=, #clear_floating, #dom_id, #dom_id=, #each, #empty?, #id, #id=, #length, #method_missing, #to_ary
Constructor Details
#initialize(params) ⇒ Form_Field
Returns a new instance of Form_Field.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/aurita-gui/form/form_field.rb', line 33 def initialize(params) # @value = params[:value] raise Form_Error.new('Must provide parameter :name for ' << self.class.to_s) unless params[:name] @form = params[:parent] @form ||= params[:form] @label = params[:label] # Get value from params unless set by derived constructor: @value = params[:value] unless @value # Do not delete parameter value, as it is a # standard for <input> elements. # Field types not supporting the value attribute # (Textarea_Field, Option_Field, ...) # must delete it themselves. @readonly = false params.delete(:form) params.delete(:parent) params.delete(:label) params[:parent] = @form 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
#form ⇒ Object
Returns the value of attribute form.
31 32 33 |
# File 'lib/aurita-gui/form/form_field.rb', line 31 def form @form end |
#label ⇒ Object
Returns the value of attribute label.
31 32 33 |
# File 'lib/aurita-gui/form/form_field.rb', line 31 def label @label end |
#type ⇒ Object
Returns the value of attribute type.
31 32 33 |
# File 'lib/aurita-gui/form/form_field.rb', line 31 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
31 32 33 |
# File 'lib/aurita-gui/form/form_field.rb', line 31 def value @value end |
Instance Method Details
#disable! ⇒ Object
82 83 84 |
# File 'lib/aurita-gui/form/form_field.rb', line 82 def disable! @attrib[:disabled] = true end |
#editable! ⇒ Object
72 73 74 |
# File 'lib/aurita-gui/form/form_field.rb', line 72 def editable! @reaonly = false end |
#element ⇒ Object
59 60 61 |
# File 'lib/aurita-gui/form/form_field.rb', line 59 def element raise Form_Error.new('Cannot render abstract class Form_Field') end |
#enable! ⇒ Object
85 86 87 |
# File 'lib/aurita-gui/form/form_field.rb', line 85 def enable! @attrib.delete(:disabled) end |
#readonly! ⇒ Object
75 76 77 78 |
# File 'lib/aurita-gui/form/form_field.rb', line 75 def readonly! @attrib[:class] = @attrib[:class].to_s << ' readonly' @readonly = true end |
#readonly? ⇒ Boolean
79 80 81 |
# File 'lib/aurita-gui/form/form_field.rb', line 79 def readonly? @readonly end |
#readonly_element ⇒ Object
62 63 64 |
# File 'lib/aurita-gui/form/form_field.rb', line 62 def readonly_element HTML.div(@attrib) { @value } end |
#to_s ⇒ Object Also known as: string
66 67 68 69 |
# File 'lib/aurita-gui/form/form_field.rb', line 66 def to_s return element().string unless @readonly return readonly_element().string end |