[Seaside] Autocompleter activate on receiving focus

Lukas Renggli renggli at gmail.com
Wed Oct 31 09:20:55 UTC 2007

> Is it possible for an autocompleter to activate when its target  
> receives
> focus?

Call the #activate method of the autocompleter when the text input  
receives focus. In SUAutocompletionTest I quickly hacked this as  

renderContentOn: html
	html paragraph: 'Start to type a Smalltalk class-name:'.
	html paragraph: [
		html textInput
			id: 'text';
			value: text;

			" the activation "
			onFocus: (html autocompleter
				alias: 'autocompleter';
			callback: [ :value | text := value ].
		html div
			class: 'autocomplete';
			script: (html autocompleter

				" the autocompleter needs a name "
				assignTo: 'autocompleter';	
				element: 'text';
				" normally the autocompleter doesn't start before 2 characters  
have been typed "
				minChars: 0;			
				onSelected: (html request
					triggerFormElement: 'text');
				on: #renderListOn: of: self) ]

You also need to update the list renderer so that it actually displays  
something in the empty case:

renderListOn: html
	| items |
	items := Smalltalk allClasses.
	text isEmpty ifFalse: [
		items := items select: [ :each | each name includesSubstring: text  
caseSensitive: false ] ].
	html unorderedList list: (items first: (items size min: 10))

Hope this helps,

Lukas Renggli
Lukas Renggli

More information about the seaside mailing list