Class: Domkey::View::LabeledGroup
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Domkey::View::LabeledGroup
- Defined in:
- lib/domkey/view/labeled_group.rb
Overview
Interfact to CheckboxGroup and RadioGroup elements through corresponding label elements; radio and checkbox controls form a group by name attribute however they don’t have visible text indicators to the user who is looking at the page. The common strategy is to provide a lable element such that its for: attribute value maps to id: attribute value of an individual control in a group. The labels become visual indicators for the user. Clicking corresponding lable activates the control.
Instance Method Summary collapse
- #before_set ⇒ Object
-
#initialize(group) ⇒ LabeledGroup
constructor
A new instance of LabeledGroup.
-
#options ⇒ Array<String>
Label texts for all elements in a group.
- #set(value) ⇒ Object
-
#value ⇒ Array<String>
Label texts for selected elements.
Constructor Details
#initialize(group) ⇒ LabeledGroup
Returns a new instance of LabeledGroup.
15 16 17 |
# File 'lib/domkey/view/labeled_group.rb', line 15 def initialize group __setobj__(group) end |
Instance Method Details
#before_set ⇒ Object
19 20 21 |
# File 'lib/domkey/view/labeled_group.rb', line 19 def before_set __getobj__.set false end |
#options ⇒ Array<String>
Returns label texts for all elements in a group.
37 38 39 |
# File 'lib/domkey/view/labeled_group.rb', line 37 def LabelMapper.for(__getobj__).map { |e| e.element.text } end |
#set(value) ⇒ Object
25 26 27 28 |
# File 'lib/domkey/view/labeled_group.rb', line 25 def set value before_set set_strategy(value) end |
#value ⇒ Array<String>
Returns label texts for selected elements.
31 32 33 34 |
# File 'lib/domkey/view/labeled_group.rb', line 31 def value selected_ones = __getobj__.find_all { |e| e.element.set? } LabelMapper.for(selected_ones).map { |e| e.element.text } end |