[Seaside] How do I use JQuery with Javascript variable

Francisco Martins chicoary at gmail.com
Tue Jan 31 20:34:05 UTC 2012


Johan, thanks for your answers. See below my considerations:

>
> On 30 Jan 2012, at 19:19, Francisco Martins wrote:
>
>> I saw my omission of the code snippet "addLoadscript html document:"
>> before your reply. I put also indicated halts but they were not
>> reached during the execution.
>
> Hm... I don't catch a reason why this would not work.
> Are you not getting any javascript errors in the browser console?

Yes, but I could not find the cause.

The console of Safari shows the following errors:

jqueryinactionhack:1SyntaxError: Parse error
jqueryinactionhack:1ReferenceError: Can't find variable: onLoad

>
>> Another question I have is this: the original code runs entirely in
>> Javascript on the client. There is no way to do the same in Seaside
>> with JQuery?
>
> Of course you can. I just assumed you were implying a request to retrieve the value also server-side.

No. I wanted to replicate the functionality found in examples from the
book JQuery in Action. It seems to me that the unobtrusive style is
not feasible in Seaside with JQuery.

>
> If you do not need the value server-side, I would not write that piece of JS using Seaside's jQuery-Javascript wrappers. You can either include the script in a function defined in an external file or write it directly in a string:
>
> html button
>        onClick: <entire js script in a Smalltalk string -- or function call to the script included in an external file>

I tried this with the code below:

html
				div: [html button type: #button;
						 id: #testButton;
						 class: #green90x24;
						 onClick: self javascriptStream;
						 with: 'Which?'].
						
JQIARadioGroupExample>>javascriptStream
	^ JSStream new nextPutAll: 'var checkedValue = $(';
		 nextPut: $';
		 nextPutAll: '[name=';
		 nextPut: $";
		 nextPutAll: 'someRadioGroup';
		 nextPut: $";
		 nextPutAll: ']:radio:checked';
		 nextPut: $';
		 nextPutAll: ').val();';
		 nextPutAll: '$(';
		 nextPut: $';
		 nextPutAll: '#result';
		 nextPut: $';
		 nextPutAll: ').html(';
		 nextPut: $';
		 nextPutAll: 'The radio element with value <tt>';
		 nextPut: $';
		 nextPutAll: ' + checkedValue +';
		 nextPut: $';
		 nextPutAll: '</tt> is checked.';
		 nextPut: $';
		 nextPutAll: ');'
		
Almost works. However does not show the value of the radio button
selected. Always shows the same string "on".
-- 
Sds.,

Francisco Ary Martins
http://chicoary.wordpress.com
----
"A filosofia não é senão uma poesia sofisticada."
Montaigne


More information about the seaside mailing list