[Seaside-dev] Enhancement to select tag

Louis LaBrunda Lou at Keystone-Software.com
Sat Mar 28 17:30:28 UTC 2009


Hi All,

I have a need to have the values of options that are the list of a select
tag be the same as the keys from a collection of associations and the
labels to be the values of the associations.  So both Smalltalk and
javascript code can do work based upon the selected value.  I only need the
key of the selected item returned.  And want it linked to the setter/getter
of the component that generates the select tag.  I have extended
#WACollectionTag with:

connectTo: aSelector of: anObject
	"Connect the instance variable represented by the selector symbol
(setter/getter) of the object to the result of the selection."

	self name: (canvas callbacks registerCallback: (MessageSend receiver:
anObject selector: aSelector asMutator)).

to aid in this effort.  I don't really like the name of the method
(#connectTo:of:) but it works.

I use the following code to render the select and option tags.  Using the
symbol of the getter/setter for both the default value and the result of
the select.

renderConnectToSelectOn: html for: anOrderedCollection to: aSymbol
	"Render a connectTo select for the collection on the canvas (html)
connected to the symbol."
	| defaultSelectionValue |

	defaultSelectionValue := self perform: aSymbol.
	html select connectTo: aSymbol of: self; with: [
		anOrderedCollection do: [:a |
			html option value: a key; label: a value; selected: (a key =
defaultSelectionValue).
		].
	].

Attached are fileouts of the extension to #WACollectionTag and a sample
component that demonstrates its use.

My thanks to Lukas for putting me on this track.  I would like to submit my
extension to #WACollectionTag, (maybe with a better method name) to aid
others to use the select tag in the same way.

I am confused as to why Seaside needs to generate the names/values for the
option tags of a select tag.  I can see that the name for the select tag
needs to be controlled by Seaside like other inputs.  Lukas explained that
Seaside needed to generate the names/values for the option tag:

"Seaside takes care of the value attribute of option tags, similar as
it does with all other names on a page. This is to ensure uniqueness,
even if different components or multiple instances of the same
component are displayed at once."

I am a NOOB to both Seaside and HTML, and I have great respect for all the
developers of Seaside, so I will take his word for it.  As there is only
one value returned for the select (not counting multi-selects) and linked
to one set of a getter/setter and the values of all the options are not
returned, and are not linked to any getter/setters, why does Seaside need
to control their values in the way it controls other input field names?

Respectively, maybe someone who know a lot more than me can revisit the
choice of Seaside generating the option values/names for a select.  If
there really isn't a need for Seaside to generate the option values instead
of using the keys from associations, the rendering of the select tag and
its use by developers could be simplified.

Thanks you for your time and thoughts and if I am way off on this, please
set me straight.

Lou 
-----------------------------------------------------------
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon
mailto:Lou at Keystone-Software.com http://www.Keystone-Software.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KscSeasideTestSelect.st
Type: application/octet-stream
Size: 2016 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/seaside-dev/attachments/20090328/1406e125/KscSeasideTestSelect.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WACollectionTag.st
Type: application/octet-stream
Size: 325 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/seaside-dev/attachments/20090328/1406e125/WACollectionTag.obj


More information about the seaside-dev mailing list