Class: Aurita::GUI::Radio_Field
- Inherits:
-
Options_Field
- Object
- Element
- Form_Field
- Options_Field
- Aurita::GUI::Radio_Field
- Defined in:
- lib/aurita-gui/form/radio_field.rb
Overview
Factory for radio input fields, specialization of Options_Field. Example:
r = Radio_Field.new(:name => :color,
:value => :red,
:label => 'Select a color',
:options => { :red => 'red color', :blue => 'blue color' })
Same as
r = Radio_Field.new(:name => :color, :value => :red, :label => 'Select a color') {
:red => 'red color', :blue => 'blue_color
}
For usage details see documentation of Options_Fiels.
Instance Attribute Summary
Attributes inherited from Options_Field
#option_labels, #options, #options_range, #value
Attributes inherited from Form_Field
Attributes inherited from Element
#attrib, #content, #parent, #tag, #type
Instance Method Summary collapse
-
#element ⇒ Object
Renders this radio field to a HTML.ul element, including options from #option_elements.
-
#option_elements ⇒ Object
Returns array of option elements for this radio field.
Methods inherited from Options_Field
#[], #[]=, #add_option, #content, #initialize
Methods inherited from Form_Field
#disable!, #editable!, #enable!, #initialize, #readonly!, #readonly?, #readonly_element, #to_s
Methods inherited from Element
#+, #[], #[]=, #clear_floating, #dom_id, #dom_id=, #each, #empty?, #id, #id=, #initialize, #length, #method_missing, #string, #to_ary
Constructor Details
This class inherits a constructor from Aurita::GUI::Options_Field
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element
Instance Method Details
#element ⇒ Object
Renders this radio field to a HTML.ul element, including options from #option_elements.
49 50 51 52 53 |
# File 'lib/aurita-gui/form/radio_field.rb', line 49 def element HTML.ul(:class => :radio_options) { option_elements().map { |o| HTML.li() { o } } } end |
#option_elements ⇒ Object
Returns array of option elements for this radio field. Each option is a radio input field with
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/aurita-gui/form/radio_field.rb', line 30 def option_elements = [] @option_elements.each { |option| if option.kind_of? Hash then option.each_pair { |k,v| << HTML.input(:type => :radio, :value => k, :name => @attrib[:name] ) { v } } elsif option.kind_of? Element then option.name = @attrib[:name] option.tag = :input option.type = :radio << option end } end |