Class: Aurita::GUI::Checkbox_Field

Inherits:
Options_Field show all
Defined in:
lib/aurita-gui/form/checkbox_field.rb

Overview

Factory for checkbox input fields, specialization of Options_Field. For usage see documentation of Options_Fiels.

Direct Known Subclasses

Boolean_Field

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

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

#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



32
33
34
35
36
37
38
39
# File 'lib/aurita-gui/form/checkbox_field.rb', line 32

def element
  element_attrib = @attrib.dup.update({ :class => :checkbox_options })
  element_attrib.delete(:name)
  element_attrib.delete(:value)
  HTML.ul(element_attrib) { 
    option_elements().map { |o| HTML.li() { o } } 
  }
end

#option_elementsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/aurita-gui/form/checkbox_field.rb', line 12

def option_elements
  elements = []
  options().each_pair { |k,v|
    box_attribs = { :type => :checkbox, 
                    :value => k, 
                    :name => @attrib[:name] }
    if @value.is_a?(Array) then
      checked = (@value.map { |v| v.to_s }.include?(k))? true : nil
    else
      checked = (@value && k.to_s == @value.to_s)? true : nil
    end
    box_attribs[:checked] = checked
    element = []
    element << HTML.input(box_attribs) 
    element << HTML.label(:for => option_id) { v } if v
    elements << element
  }
  elements
end