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 }



298
299
300
# File 'lib/vapir-common/elements/elements.rb', line 298

def [](index)
  options[index]
end

#clearObject Also known as: clearSelection

Clears the selected items in the select box.



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/vapir-common/elements/elements.rb', line 303

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



359
360
361
# File 'lib/vapir-common/elements/elements.rb', line 359

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)


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

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



290
291
292
293
294
# File 'lib/vapir-common/elements/elements.rb', line 290

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.



327
328
329
# File 'lib/vapir-common/elements/elements.rb', line 327

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.



339
340
341
# File 'lib/vapir-common/elements/elements.rb', line 339

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

#selected_option_textsObject



370
371
372
# File 'lib/vapir-common/elements/elements.rb', line 370

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)


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

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.


366
367
368
# File 'lib/vapir-common/elements/elements.rb', line 366

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