Class: Aurita::GUI::Radio_Field
- Inherits:
-
Options_Field
- Object
- Array
- 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, #option_values, #value
Attributes inherited from Form_Field
#data_type, #form, #hidden, #hint, #invalid, #label, #required, #type, #value
Attributes inherited from Element
#attrib, #force_closing_tag, #gui_element_id, #parent, #tag
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, i.e.
Methods inherited from Options_Field
#[], #[]=, #add_option, #content, #initialize, #option_hash, #options, #options=, #readonly_element
Methods inherited from Form_Field
#disable!, #disabled=, #editable!, #enable!, #hidden?, #hide!, #initialize, #invalid!, #invalid?, #optional!, #readonly!, #readonly=, #readonly?, #readonly_element, #required!, #required?, #show!, #to_hidden_field, #to_s
Methods inherited from Element
#+, #<<, #[], #[]=, #add_class, #aurita_gui_element, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #initialize, #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
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.
44 45 46 47 48 |
# File 'lib/aurita-gui/form/radio_field.rb', line 44 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, i.e. an array of <input type=“checkbox” … />. Each option is a radio input field with
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/aurita-gui/form/radio_field.rb', line 30 def option_elements elements = [] ().each_pair { |k,v| element = [] selected = (@value.to_s == k.to_s)? true : nil element << HTML.input(:type => :radio, :value => k, :name => @attrib[:name], :checked => selected ) element << HTML.label(:for => option_id) { v } if v elements << element } elements end |