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, #options, #options_range, #value

Attributes inherited from Form_Field

#form, #label, #type, #value

Attributes inherited from Element

#attrib, #content, #parent, #tag, #type

Instance Method Summary collapse

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

#elementObject



49
50
51
52
53
# File 'lib/aurita-gui/form/checkbox_field.rb', line 49

def element
  HTML.ul(:class => :checkbox_options) { 
    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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/aurita-gui/form/checkbox_field.rb', line 12

def option_elements
  options = []
  @option_elements.each { |option| 
    if option.kind_of? Hash then
      # Options have been set as value/label pair, like 
      #
      #  @options = { 1 => 'first', 2 => 'second' }
      #
      option.each_pair { |k,v|
        box_attribs = { :type => :checkbox, 
                        :value => k, 
                        :name => @attrib[:name] }
        box_attribs[:checked] = true if (v.to_s == @value.to_s)
        options << HTML.input(box_attribs)
      }
    elsif option.kind_of? Element then
      # Option element has been built externally, like in 
      #
      #  @options = [ HTML.option(:class => :custom, :label => 'built manually') ]
      #
      option.name = @attrib[:name]
      option.tag = :input
      option.type = :checkbox
      options << option
    else 
      # For  @options = [ :foo, :bar, 'wombat' ], 
      #
      box_attribs = { :type => :checkbox, 
                      :value => option.to_s, 
                      :name => @attrib[:name] }
      box_attribs[:checked] = true if (option.to_s == @value.to_s)
      options << HTML.input(box_attribs)
    end
  }
  options
end