[Seaside] Form.Element.Observer / Callback mix-up?

Ken Treis ken at miriamtech.com
Wed Aug 8 00:41:22 UTC 2007

I'm building a "live search" using Form.Element.Observer from  
prototype.js, which (as far as I can tell) hasn't been implemented in  
SeasideScriptaculous yet. So I'm trying to build the Javascript  
manually, and I'm seeing some weird behavior on the Ajax callbacks.

I've distilled the problematic code down to this:

> LiveSearchComponent>>renderContentOn: html
> 	html
> 		script: 'function doSearch() { '
> 				, ((html updater)
> 						id: 'results';
> 						triggerForm: 'form';
> 						callback: [:r | self renderSearchResultsOn: r]) displayString
> 					, ' }'.
> 	(html form)
> 		id: 'form';
> 		with:
> 				[html paragraph: 'What is your first name?'.
> 				(html textInput)
> 					id: 'first';
> 					callback: [:val | first := val].
> 				html paragraph: 'And your last name?'.
> 				(html textInput)
> 					id: 'last';
> 					callback: [:val | last := val].
> 				"declare doSearch() above here, and it works properly."
> 				(html submitButton)
> 					callback:
> 							[Transcript
> 								show: 'Submit callback';
> 								cr];
> 					value: 'Next'
> 				"declare doSearch() below here, and it triggers the submit  
> callback and renders its result instead."].
> 	html div id: 'results'.
> 	html
> 		script: 'new Form.Element.Observer("first", 1, doSearch); new  
> Form.Element.Observer("last", 1, doSearch);'

> LiveSearchComponent>>renderSearchResultsOn: html
> 	html
> 		paragraph: 'Nothing found matching (' , first printString , ' ',  
> last printString , ')'

The problem is that, if I declare the doSearch function at the top of  
renderContentOn:, it works as expected. But if I declare it below the  
submitButton rendering, the callback associated with the submit  
button gets fired -- and then the entire component gets rendered in  
the results area, as if the Ajax request had triggered  
#renderContentOn: instead of #renderSearchResultsOn:.

I can certainly work around the issue, by declaring my little helper  
script above the form. But I'm sure I'm probably doing something  
wrong here. If there's a cleaner way of doing this, I'd love to hear  
about it -- especially if it solves the weirdness too.


Ken Treis
Miriam Technologies, Inc.

More information about the Seaside mailing list