Class: SWS::CheckBoxList

Inherits:
MultipleSelectionList show all
Defined in:
lib/sws/Core/components/CheckBoxList/CheckBoxList.rb

Overview

Represents a list of checkboxes with the same name. Bindings:

  • list (required) - array of object to iterate in the checkboxes

  • item (required, settable) - an object to use as iterator

  • display_string - use it if the string to display at a checkbox is not the

item itself

  • selections (required,settable) - the array of selected items (not the

displayed strings, but the objects)

  • prefix - HTML code to add before each checkbox

  • suffix - HTML code to add after each checkbox

  • disabled - if true, the list will be rendered inactive

  • other_tag_string - generic string to add to the end of each <INPUT

type=checkbox tag

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

Methods inherited from MultipleSelectionList

#process_bindings, #selections, #selections=

Methods inherited from ListElement

#append_to_response, #item, #list

Methods inherited from FormElement

#container?, #element_name

Methods inherited from Component

#api_filename, #app, #append_to_response, #awake, #container?, #content?, create, #create_component_tree, #definition_filename, #initialize, #page, #perform_action, #process_bindings, #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

#generate_htmlObject

Generates the HTML code for the component.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sws/Core/components/CheckBoxList/CheckBoxList.rb', line 20

def generate_html ()

	string = ""
	generic_string = generic_attr_string()
	list().each_index do |index|
		item = list[index]
		@slots["item"].value = item
		if ( slot_bound?( "display_string" ))
			display_string = @slots["display_string"].value()
		else
			display_string = item
		end
		if ( slot_bound?( "prefix" ))
			string << @slots["prefix"].value()
		end
		string << "<INPUT type=\"checkbox\" name=\"#{element_name()}.selections\" value=#{index}"
		if ( slot_bound?( "disabled" ) && @slots["disabled"].value() == true )
			string << " disabled"
		end
		if ( selections().include?( item ) )
			string << " checked"
		end
		string << generic_string << ">\n"
		string << display_string
		if ( slot_bound?( "suffix" ) )
			string << @slots["suffix"].value()
		end
	end
	return string

end