Class: Dill::Select

Inherits:
Field show all
Defined in:
lib/dill/widgets/select.rb

Overview

A select.

Instance Method Summary collapse

Methods inherited from Field

root

Methods inherited from Widget

#absent?, action, #classes, #click, #diff, filter, filter?, find_all_in, find_in, #gone?, #has_action?, #id, #initialize, #inspect, #present?, present_in?, root, #root, selector, #text, #value, widget_delegator

Methods included from Widgets::DSL

#form, #list, #widget

Methods included from WidgetParts::Container

#has_no_widget?, #has_widget?, #widget, #widgets

Methods included from WidgetParts::Struct

included

Constructor Details

This class inherits a constructor from Dill::Widget

Instance Method Details

#getString

Returns The text of the selected option.

Returns:

  • (String)

    The text of the selected option.



5
6
7
8
9
# File 'lib/dill/widgets/select.rb', line 5

def get
  option = root.find('[selected]') rescue nil

  option && option.text
end

#set(option) ⇒ Object

Selects the given option.

You may pass in the option text or value.



14
15
16
17
18
19
20
21
22
# File 'lib/dill/widgets/select.rb', line 14

def set(option)
  root.find(:option, option).select_option
rescue
  begin
    root.find("option[value = #{option.inspect}]").select_option
  rescue Capybara::ElementNotFound => e
    raise wrap_exception(e, InvalidOption)
  end
end

#to_cellObject



29
30
31
# File 'lib/dill/widgets/select.rb', line 29

def to_cell
  get
end

#to_sObject

Returns the text of the selected option, or the empty string if no option is selected.

Returns:

  • the text of the selected option, or the empty string if no option is selected.



27
# File 'lib/dill/widgets/select.rb', line 27

def_delegator :get, :to_s