<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 7, 2014 at 6:02 PM, Johan Brichau <span dir="ltr">&lt;<a href="mailto:johan@inceptive.be" target="_blank">johan@inceptive.be</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mariano,<br>
<br>
Unfortunately, the trick with capturing &#39;this&#39; for later use is not going to work. The generated script (or the onSuccess callback) are not executed in the same scope as where you defined &#39;myself&#39;.<br>
</blockquote><div><br></div><div>Ok, I imagined that something like that could happen. </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I made that mistake in this thread earlier on, but I was just not thinking right. Sorry about that.<br>

<br></blockquote><div><br></div><div>Np, it was a good try to avoid having an id for every row ;)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The problem with the apply: is that the apply statement is added inside the function. I noticed that problem with JSFunction objects before but I don&#39;t know yet if it can be solved. It does act counter-intuitive though.<br>

<br></blockquote><div><br></div><div>Indeed.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Working with an id per row is the easiest solution here, I think.<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote><div><br></div><div>OK, perfect. </div><div><br></div><div>Thank you very much guys, </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888">
Johan<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 07 Jul 2014, at 15:42, Mariano Martinez Peck &lt;<a href="mailto:marianopeck@gmail.com">marianopeck@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Thank you all for the explanations. I do get it now. Now that I made the simplest case to work (adding an id per tr), I would like to make the Johan solution (finding the closest tr). I tried:<br>
&gt;<br>
&gt;       html form: [<br>
&gt;               html label:[<br>
&gt;                       html checkbox<br>
&gt;                                onClick:  (((JSStream on: &#39;var myself = this&#39;),<br>
&gt;                                               (html jQuery ajax<br>
&gt;                                                         serializeThisWithHidden;<br>
&gt;                                                         script: [ :s | s &lt;&lt; (((s jQuery expression:(JSStream on: &#39;myself&#39;)) closest: &#39;tr&#39;) addClass: &#39;selectedRow&#39;) ])) asFunction apply: #());<br>

&gt;                               value: (self isSelected: anObject);<br>
&gt;                               callback: [ :value | self selectRow: anObject value: value ]]]<br>
&gt;<br>
&gt; But I get: SyntaxError: function statement requires a name<br>
&gt;<br>
&gt;<br>
&gt; The onClick is being generated like this:<br>
&gt;<br>
&gt; a JSFunction (function(){var myself = this;$.ajax({&quot;url&quot;:&quot;/reps&quot;,&quot;data&quot;:[&quot;_s=nHl8jzTmLkMbcOME&quot;,&quot;_k=2IH4kmR1ds-rEaua&quot;,&quot;accessMenu=Clients&quot;,&quot;activityMenu=Clients&quot;,&quot;65&quot;,$(this).next(&quot;input:hidden&quot;).andSelf().serialize()].join(&quot;&amp;&quot;),&quot;dataType&quot;:&quot;script&quot;})}())<br>

&gt;<br>
&gt; Note that if I put a halt in #script, it doesn&#39;t even get call.<br>
&gt;<br>
&gt; I removed the asFunction apply:   letting only something like this:<br>
&gt;<br>
&gt;  onClick:  (((JSStream on: &#39;var myself = this&#39;),<br>
&gt;                 (html jQuery ajax<br>
&gt;                           serializeThisWithHidden;<br>
&gt;                           script: [ :s |  self halt. s &lt;&lt; (((s jQuery expression:(JSStream on: &#39;myself&#39;)) closest: &#39;tr&#39;) addClass: &#39;selectedRow&#39;) ])) );<br>
&gt;<br>
&gt; This solved that problem, but my row doesn&#39;t get the css class yet. The #script: does halts, and generates a script like this one:<br>
&gt;<br>
&gt; a JSScript ($(myself).closest(&quot;tr&quot;).addClass(&quot;selectedRow&quot;))<br>
&gt;<br>
&gt; Any ideas?<br>
&gt;<br>
&gt; Thanks in advance,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Sun, Jul 6, 2014 at 9:14 AM, Johan Brichau &lt;<a href="mailto:johan@inceptive.be">johan@inceptive.be</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; Both in the context of the #script: ajax callback-to-smalltalk and the ajax #onSuccess: javascript-callback option, the javascript&#39;s this variable will not hold anything related to the DOM.<br>
&gt;<br>
&gt; The difference between #script: and #onSuccess: is that the former defines a script rendering callback to be executed in Seaside and the latter is a jQuery ajax option to define a javascript callback (to be executed client-side) when the ajax call finishes successfully.<br>

&gt;<br>
&gt; The onSuccess parameter will accept both a string or a JSScript instance as a Javascript to be executed<br>
&gt; In a #script callback, the block argument is a JSScript instance already. The script concatenation operator &#39;&lt;&lt;&#39; expects another JSScript instance (e.g. a JSStream instance). If you concatenate a Smalltalk string with a JSScript instance, the Smalltalk string is serialized as a Javascript string on the JSScript instance.<br>

&gt;<br>
&gt; cheers<br>
&gt; Johan<br>
&gt;<br>
&gt; On 06 Jul 2014, at 01:06, carlo.t &lt;<a href="mailto:snoobabk@yahoo.ie">snoobabk@yahoo.ie</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt; Hi<br>
&gt; &gt;<br>
&gt; &gt; I thick #script: does not work because this is a separate ajax call where<br>
&gt; &gt; the reference to &#39;this&#39; is not known and is not the row you expect.<br>
&gt; &gt; #script would work if you reference a valid DOM id for the row e.g.<br>
&gt; &gt;                                       html checkbox<br>
&gt; &gt;                                               onClick: (html jQuery ajax serializeThisWithHidden;<br>
&gt; &gt;                                                               script: [:s | s<br>
&gt; &gt;                                                                               &lt;&lt; (s jQuery: #idForRow) addClass: &#39;selectedRow&#39;]);<br>
&gt; &gt;<br>
&gt; &gt; #onSuccess is probably triggering a callback where the reference to &#39;this&#39;<br>
&gt; &gt; is valid and so the following line will work:<br>
&gt; &gt;       (html jQuery this closest: &#39;tr&#39;) addClass: &#39;selectedRow&#39;<br>
&gt; &gt;<br>
&gt; &gt; I&#39;m a javascript newbie too but thats what I think is going on.<br>
&gt; &gt;<br>
&gt; &gt; Cheers<br>
&gt; &gt; Carlo<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; --<br>
&gt; &gt; View this message in context: <a href="http://forum.world.st/Checkbox-and-AJAX-tp4731692p4766717.html" target="_blank">http://forum.world.st/Checkbox-and-AJAX-tp4731692p4766717.html</a><br>
&gt; &gt; Sent from the Seaside General mailing list archive at Nabble.com.<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; seaside mailing list<br>
&gt; &gt; <a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
&gt; &gt; <a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; seaside mailing list<br>
&gt; <a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
&gt; <a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Mariano<br>
&gt; <a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br>
&gt; _______________________________________________<br>
&gt; seaside mailing list<br>
&gt; <a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
&gt; <a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
<br>
_______________________________________________<br>
seaside mailing list<br>
<a href="mailto:seaside@lists.squeakfoundation.org">seaside@lists.squeakfoundation.org</a><br>
<a href="http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside" target="_blank">http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Mariano<br><a href="http://marianopeck.wordpress.com" target="_blank">http://marianopeck.wordpress.com</a><br>
</div></div>