Class: Metallize::Form::MultiSelectList
- Extended by:
- ElementMatcher
- Defined in:
- lib/metallize/form/multi_select_list.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Field
Instance Method Summary collapse
-
#initialize(node) ⇒ MultiSelectList
constructor
A new instance of MultiSelectList.
-
#select_none ⇒ Object
Select no options.
-
#selected_options ⇒ Object
Get a list of all selected options.
- #value ⇒ Object
- #value=(values) ⇒ Object
Methods included from ElementMatcher
Methods inherited from Field
Constructor Details
#initialize(node) ⇒ MultiSelectList
Returns a new instance of MultiSelectList.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/metallize/form/multi_select_list.rb', line 7 def initialize node value = [] @options = [] # parse node.find_elements(:tag_name, 'option').each do |n| @options << Metallize::Form::Option.new(n, self) end super node, value end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/metallize/form/multi_select_list.rb', line 5 def @options end |
Instance Method Details
#select_none ⇒ Object
Select no options
23 24 25 26 |
# File 'lib/metallize/form/multi_select_list.rb', line 23 def select_none @value = [] .each { |o| o.untick } end |
#selected_options ⇒ Object
Get a list of all selected options
41 42 43 |
# File 'lib/metallize/form/multi_select_list.rb', line 41 def @options.find_all { |o| o.selected? } end |
#value ⇒ Object
45 46 47 48 49 50 |
# File 'lib/metallize/form/multi_select_list.rb', line 45 def value value = [] value.concat @value value.concat .map { |o| o.value } value.first end |
#value=(values) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/metallize/form/multi_select_list.rb', line 28 def value=(values) select_none [values].flatten.each do |value| option = .find { |o| o.value == value } if option.nil? @value.push(value) else option.node.click end end end |