Class: SWS::MultipleSelectionList
- Inherits:
-
ListElement
- Object
- Component
- FormElement
- ListElement
- SWS::MultipleSelectionList
- Defined in:
- lib/sws/component.rb
Overview
Base class for lists with multiple selections allowed: CheckBoxList and Select
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Component
#action_components, #definition_component, #encoding, #html_attrs, #method_to_call, #name, #parameters, #parent, #request, #request_number, #slots, #subcomponents, #tokens
Instance Method Summary collapse
-
#process_bindings ⇒ Object
#if ( selections == nil ) #nothing is selected - return empty array #@slots.value = Array.new() #else #WARNING: selections will be an Array if multiple and a single object if not selected = Array.new() #if we have single selection, make it an Array selections = [selections] unless ( selections.is_a? (Array) ) #in the selections array we have indices of elements in “list” array selections.each { |sel| selected << list } @slots.value = selected end end.
-
#selections ⇒ Object
Returns value of “selections” slot or empty Array instead of nil.
-
#selections=(selections) ⇒ Object
Sets the value of the “selections” slot.
Methods inherited from ListElement
#append_to_response, #item, #list
Methods inherited from FormElement
Methods inherited from Component
#api_filename, #app, #append_to_response, #awake, #container?, #content?, create, #create_component_tree, #definition_filename, #initialize, #page, #perform_action, #process_parameters, #process_request, #remove_subcomponents, #session, #set_request_subcomponents, #sleep, #slot_bound?, #subcomponent_for_name, synchronize_slot, #synchronize_slot?, #synchronize_slots, #template_filename, #tokenize_binding, #update_binding, #url_string
Constructor Details
This class inherits a constructor from SWS::Component
Instance Method Details
#process_bindings ⇒ Object
#if ( selections == nil ) #nothing is selected - return empty array #@slots.value = Array.new() #else #WARNING: selections will be an Array if multiple and a single object if not selected = Array.new() #if we have single selection, make it an Array selections = [selections] unless ( selections.is_a? (Array) ) #in the selections array we have indices of elements in “list” array selections.each { |sel| selected << list } @slots.value = selected end end
645 646 647 648 649 650 651 |
# File 'lib/sws/component.rb', line 645 def process_bindings () if ( @parameters["selections"] ) self.selections = @parameters["selections"] else self.selections = nil end end |
#selections ⇒ Object
Returns value of “selections” slot or empty Array instead of nil
601 602 603 604 |
# File 'lib/sws/component.rb', line 601 def selections () @selections ||= (@slots["selections"].value() || Array.new ) return @selections end |
#selections=(selections) ⇒ Object
Sets the value of the “selections” slot
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/sws/component.rb', line 608 def selections= ( selections ) if ( selections == nil ) @slots["selections"].value = [] elsif ( selections.is_a?( Array ) ) #in the selections array we have indices of elements in "list" array selected = selections.collect { |sel| list[sel.to_i] } @slots["selections"].value = selected else #single value - create an Array containing it if ( selections == "__empty_string" ) @slots["selections"].value = nil else @slots["selections"].value = [ list[selections.to_i] ] end end end |