Class: UnderOs::UI::Form
Constant Summary
Constants included from Wrap
Wrap::INSTANCES_CACHE, Wrap::RAW_WRAPS_MAP, Wrap::WRAPS_TAGS_MAP
Instance Method Summary collapse
- #disable ⇒ Object
- #elements ⇒ Object
- #enable ⇒ Object
- #focus ⇒ Object
- #inputs ⇒ Object
- #values ⇒ Object
Methods inherited from View
Methods included from Manipulation
#append, #clear, #insert, #insertTo, #prepend, #remove
Methods included from Traversing
#children, #empty?, #find, #first, #matches, #parent, #siblings
Methods included from Dimensions
#position, #position=, #size, #size=
Methods included from Animation
#animate, #fade_in, #fade_out, #highlight
Methods included from Commons
#data, #data=, #hidden, #hide, #id, #id=, #page, #show, #tagName, #toggle, #visible
Methods included from Styles
#addClass, #className, #className=, #classNames, #classNames=, #hasClass, #radioClass, #removeClass, #repaint, #style, #style=, #toggleClass
Methods included from Events
Methods included from Wrap
Constructor Details
This class inherits a constructor from UnderOs::UI::View
Instance Method Details
#disable ⇒ Object
45 46 47 48 |
# File 'lib/under_os/ui/form.rb', line 45 def disable elements.each(&:disable) self end |
#elements ⇒ Object
4 5 6 7 8 |
# File 'lib/under_os/ui/form.rb', line 4 def elements find('*').select do |view| view.is_a?(UnderOs::UI::Input) || view._.is_a?(UIButton) end end |
#enable ⇒ Object
50 51 52 53 |
# File 'lib/under_os/ui/form.rb', line 50 def enable elements.each(&:enable) self end |
#focus ⇒ Object
55 56 57 58 59 |
# File 'lib/under_os/ui/form.rb', line 55 def focus if input = inputs.first input.focus end end |
#inputs ⇒ Object
10 11 12 13 14 |
# File 'lib/under_os/ui/form.rb', line 10 def inputs find('*').select do |view| view.is_a?(UnderOs::UI::Input) end end |
#values ⇒ Object
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 |
# File 'lib/under_os/ui/form.rb', line 16 def values {}.tap do |values| inputs.each do |input| next if input.disabled || ! input.name || (input.is_a?(UnderOs::UI::Switch) && !input.checked) hash = values; key = nil keys = input.name.scan(/[^\[]+/) # getting throught the smth[smth][smth][] in the name while keys.size > 1 key = keys.shift key = key.slice(0, key.size-1) if key.ends_with?(']') hash[key] = keys[0] == ']' ? [] : {} if ! hash[key] hash = hash[key] end key = keys.shift key = key.slice(0, key.size-1) if key.ends_with?(']') if hash.is_a?(Array) hash << input.value else hash[key] = input.value end end end end |