Class: SWS::SubmitButton

Inherits:
FormElement show all
Defined in:
lib/sws/Core/components/SubmitButton/SubmitButton.rb

Overview

Represents <INPUT type=submit HTML tag Bindings:

  • value (required,default: “Submit”) - string to be displayed on the button.

  • action - method to be called on button click

  • other_tag_string - generic string to add to the 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 FormElement

#container?, #element_name

Methods inherited from Component

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

Constructor Details

#initialize(*args) ⇒ SubmitButton

Returns a new instance of SubmitButton.



11
12
13
14
# File 'lib/sws/Core/components/SubmitButton/SubmitButton.rb', line 11

def initialize (*args)
	super
	@action = nil
end

Instance Method Details

#append_to_response(response) ⇒ Object

Appends #generate_html() output to response



41
42
43
# File 'lib/sws/Core/components/SubmitButton/SubmitButton.rb', line 41

def append_to_response ( response )
	response << generate_html()
end

#generate_htmlObject

Generates HTML output containing <INPUT type=“submit” tag



47
48
49
# File 'lib/sws/Core/components/SubmitButton/SubmitButton.rb', line 47

def generate_html ()
	return "<INPUT TYPE=\"submit\" NAME=\"#{element_name()}.value\" VALUE=\"#{@slots["value"].value}\"#{generic_attr_string()}>"
end

#perform_actionObject

If the action has been set up (see #update_binding( key,value )) it is called now. Otherwise just nil is returned.



29
30
31
32
33
34
35
36
37
# File 'lib/sws/Core/components/SubmitButton/SubmitButton.rb', line 29

def perform_action ()

	if ( @action )
		return @action.call()
	else
		return nil
	end

end

#update_binding(key, value) ⇒ Object

Overriden method from Component class - sets the action to perform if the “value” parameter is not empty



18
19
20
21
22
23
24
# File 'lib/sws/Core/components/SubmitButton/SubmitButton.rb', line 18

def update_binding ( key, value )

	if ( key == "value" )
		@action = @slots["action"].bound_object()
	end

end