Class: Domino::Form::SelectField
- Defined in:
- lib/domino/form/select_field.rb
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
-
#callback ⇒ Object
Any callback mapping on a select will recieve one or more option nodes.
-
#read(node) ⇒ Object
Returns the set of selected options that can be processed in the callback.
- #value(node) ⇒ Object
- #write(node, value) ⇒ Object
Methods inherited from Field
#extract_field_options, #field, #initialize
Constructor Details
This class inherits a constructor from Domino::Form::Field
Instance Method Details
#callback ⇒ Object
Any callback mapping on a select will recieve one or more option nodes. Applying to one item or an Enumerable.
34 35 36 |
# File 'lib/domino/form/select_field.rb', line 34 def callback @callback ||= :value.to_proc end |
#read(node) ⇒ Object
Returns the set of selected options that can be processed in the callback.
3 4 5 6 7 |
# File 'lib/domino/form/select_field.rb', line 3 def read(node) s = field(node) selected = s.all('option[selected]') s.multiple? ? selected : selected.first end |
#value(node) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/domino/form/select_field.rb', line 22 def value(node) val = read(node) return val unless callback if field(node).multiple? val.map { |opt| callback.call(opt) } else callback.call(val) end end |
#write(node, value) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/domino/form/select_field.rb', line 9 def write(node, value) s = field(node) values = Array(value) s.all('option').each do |o| if values.include?(o.text) || values.include?(o.value) o.select_option elsif s.multiple? o.unselect_option end end end |