Class: Aurita::GUI::Radio_Field

Inherits:
Options_Field show all
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, #parent, #tag

Instance Method Summary collapse

Methods inherited from Options_Field

#[], #[]=, #add_option, #content, #initialize, #option_hash, #options, #options=

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, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #initialize, #method_missing, #recurse, #remove_class, #set_content, #string, #swap, #to_ary, #type=

Methods included from Marshal_Helper_Class_Methods

#marshal_load

Methods included from Marshal_Helper

#marshal_dump

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

#elementObject

Renders this radio field to a HTML.ul element, including options from #option_elements.



43
44
45
46
47
# File 'lib/aurita-gui/form/radio_field.rb', line 43

def element
  HTML.ul(:class => :radio_options) { 
    option_elements().map { |o| HTML.li() { o } } 
  }
end

#option_elementsObject

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
# File 'lib/aurita-gui/form/radio_field.rb', line 30

def option_elements
  elements = []
  options().each_pair { |k,v|
    element = []
    element << HTML.input(:type => :radio, :value => k, :name => @attrib[:name] ) 
    element << HTML.label(:for => option_id) { v } if v
    elements << element
  }
  elements
end