class Domino::Form::SelectField

Public Instance Methods

callback() click to toggle source

Any callback mapping on a select will recieve one or more option nodes. Applying to one item or an Enumerable.

# File lib/domino/form/select_field.rb, line 34
def callback
  @callback ||= :value.to_proc
end
read(node) click to toggle source

Returns the set of selected options that can be processed in the callback.

# 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) click to toggle source
# 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) click to toggle source
# 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