Module: Vapir::SelectList

Extended by:
ElementHelper
Defined in:
lib/vapir-common/elements/elements.rb

Instance Method Summary collapse

Methods included from ElementHelper

add_specifier, container_collection_method, container_single_method, included

Methods included from ElementClassAndModuleMethods

#add_container_method_extra_args, #all_dom_attr_aliases, #all_dom_attrs, #class_array_append, #class_array_get, #class_hash_get, #class_hash_merge, #container_collection_methods, #container_method_extra_args, #container_single_methods, #default_how, #dom_attr, #dom_attr_locate_alias, #dom_function, #dom_setter, #element_collection, #factory, #inspect_these, #inspect_this_if, #parent_element_module, #set_or_get_class_var, #specifiers

Instance Method Details

#[](index) ⇒ Object

note that the above is defined that way rather than with element_collection, as below, because adding :select_list => self to extra isn’t implemented yet element_collection :options, :options, Option, proc { => self }



351
352
353
# File 'lib/vapir-common/elements/elements.rb', line 351

def [](index)
  options[index]
end

#clearObject Also known as: clearSelection

Clears the selected items in the select box.



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/vapir-common/elements/elements.rb', line 356

def clear
  with_highlight do
    assert_enabled
    changed=false
    options.each do |option|
      if option.selected
        option.selected=false
        changed=true
      end
    end
    if changed
      fire_event :onchange
      wait
    end
  end
end

#option_textsObject



412
413
414
# File 'lib/vapir-common/elements/elements.rb', line 412

def option_texts
  options.map{|o| o.text }
end

#option_texts_include?(text_or_regexp) ⇒ Boolean Also known as: include?, includes?

Does the SelectList have an option whose text matches the given text or regexp?

Returns:

  • (Boolean)


397
398
399
# File 'lib/vapir-common/elements/elements.rb', line 397

def option_texts_include?(text_or_regexp)
  option_texts.grep(text_or_regexp).size > 0
end

#optionsObject

Returns an ElementCollection containing all the option elements of the select list Raises UnknownObjectException if the select box is not found



343
344
345
346
347
# File 'lib/vapir-common/elements/elements.rb', line 343

def options
  assert_exists do
    ElementCollection.new(self, element_class_for(Vapir::Option), extra_for_contained.merge(:candidates => :options, :select_list => self))
  end
end

#select_text(option_text, method_options = {}) ⇒ Object Also known as: select, set

selects options whose text matches the given text. Raises NoValueFoundException if the specified value is not found.

takes method_options hash (note, these are flags for the function, not to be confused with the Options of the select list)

  • :wait => true/false default true. controls whether #wait is called and whether fire_event or fire_event_no_wait is used for the onchange event.



380
381
382
# File 'lib/vapir-common/elements/elements.rb', line 380

def select_text(option_text, method_options={})
  select_options_if(method_options) {|option| Vapir::fuzzy_match(option.text, option_text) }
end

#select_value(option_value, method_options = {}) ⇒ Object

selects options whose value matches the given value. Raises NoValueFoundException if the specified value is not found.

takes options hash (note, these are flags for the function, not to be confused with the Options of the select list)

  • :wait => true/false default true. controls whether #wait is called and whether fire_event or fire_event_no_wait is used for the onchange event.



392
393
394
# File 'lib/vapir-common/elements/elements.rb', line 392

def select_value(option_value, method_options={})
  select_options_if(method_options) {|option| Vapir::fuzzy_match(option.value, option_value) }
end

#selected_option_textsObject



423
424
425
# File 'lib/vapir-common/elements/elements.rb', line 423

def selected_option_texts
  selected_options.map{|o| o.text }
end

#selected_option_texts_include?(text_or_regexp) ⇒ Boolean Also known as: selected?

Is the specified option (text) selected? Raises exception of option does not exist.

Returns:

  • (Boolean)


404
405
406
407
408
409
# File 'lib/vapir-common/elements/elements.rb', line 404

def selected_option_texts_include?(text_or_regexp)
  unless includes? text_or_regexp
    raise Vapir::Exception::UnknownObjectException, "Option #{text_or_regexp.inspect} not found."
  end
  selected_option_texts.grep(text_or_regexp).size > 0
end

#selected_optionsObject

Returns an array of selected option Elements in this select list.

An empty array is returned if the select box has no selected item.


419
420
421
# File 'lib/vapir-common/elements/elements.rb', line 419

def selected_options
  options.select{|o|o.selected}
end