[Seaside] Setting focus on Input field in form

Avi Bryant avi at beta4.com
Tue Mar 16 10:14:00 CET 2004


On Mar 15, 2004, at 5:14 PM, Brett Taylor wrote:

> Avi,
> The following ended up working  in I.E 6 & Mozilla 1.X
>
>
> UserRegistrationForm>>script
> 	^'function setFocus() {
> 			var elem = document.getElementById("<1s>");	
> 			elem.focus();}'   expandMacrosWith: self focusFieldName

I just tried playing with this some, and here's what I came up with for 
now:

WAHtmlRenderer>>autofocus: aBlock
	| id |
	id _ 1000 atRandom.
	self cssId: id.
	aBlock value.
	self script: 'document.getElementById("', id asString, '").focus()'

This is to be used as a wrapper around a particular form element, eg,

html autofocus: [html textInputWithValue: self foo callback: [:v | self 
foo: v]]

Seems to work fine in both Safari and Mozilla.

Of course it would be nice if it only generated an ID if one wasn't 
already provided, and it should use something better than "1000 
atRandom" anyway, but it's a start.

Avi



More information about the Seaside mailing list