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 }



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

def [](index)
  options[index]
end

#clearObject Also known as: clearSelection

Clears the selected items in the select box.



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

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



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

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)


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

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



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

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.



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

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.



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

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

#selected_option_textsObject



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

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)


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

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.


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

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