[Seaside] Re: Checkbox and AJAX?
Paul DeBruicker
pdebruic at gmail.com
Sat Jul 5 14:37:14 UTC 2014
Try changing from #script: to #onSuccess:
Mariano Martinez Peck wrote
> Hi,
>
> I am back trying to make this example to work. What I cannot do is to add
> my "selectedRow" css class to the selected TR. I did this:
>
> html form: [
> html label:[
> html checkbox
> onClick:
> (html jQuery ajax
> serializeThisWithHidden;
> script: [ :s | s << ('$(''#tr', anInteger
> asString, ''').addClass(''selectedRow'');')
> ]);
> value: (self isSelected: anObject);
> callback: [ :value | self selectRow: anObject value: value ]]]
>
>
> The callbacks does work, the server gets correct etc...in fact, if I then
> refresh the page, the row is correctly applied the "selected" row. The
> problem is that I cannot make the row selected with the #script: When I
> debug, the #script: is something like:
> $('#tr4').addClass('selectedRow');
>
> But nothing happens. If I go to a JavaScript console in the browser and I
> paste the very same line, it works!
>
> Any ideas what I am doing wrong?
>
> Thanks in advance,
>
>
>
> On Tue, Dec 24, 2013 at 12:06 PM, Mariano Martinez Peck <
> marianopeck@
>> wrote:
>
>>
>>
>>
>> On Mon, Dec 23, 2013 at 12:27 PM, Johan Brichau <
> johan@
> >
>> wrote:
>>
>>>
>>> On 23 Dec 2013, at 14:15, Mariano Martinez Peck <
> marianopeck@
> >
>>> wrote:
>>>
>>> > Indeed, it seems I need this because even if I render only the table,
>>> the scroll goes up again to the top of the table....
>>>
>>> Do you replace the table or only its inner html?
>>
>>
>> I was replacing a div which is a container of the table.
>>
>>
>>> In general, to keep the scroll position of an element, you must replace
>>> its contents (and not the element itself).
>>> Perhaps in case of a table, you may only re-render the
> , and then
>>> also only replacing its inner html.
>>>
>>>
>> Ok, I will try that.
>>
>>
>>
>>> > So..which other solution you found besides explicit id per row? Of
>>> course in the server it is easy to know which row to render, the problem
>>> is
>>> how to know it in client side.
>>> > I am would be glad you listen your approaches here.
>>>
>>> You want to replace the row where the user clicked in, right?
>>>
>>
>> Yes. I just need to re-render it so that since it is selected now, it has
>> a different css.
>>
>>
>>> The $(this) will refer to the checkbox element you clicked, but not
>>> anymore in the response script. So, you need to capture it in a lexical
>>> scope.
>>>
>>>
>> ahaaaa, good point!
>>
>>
>>> This is what I would try:
>>>
>>> onClick: (((JSStream on: 'var myself = this'),
>>> (html jQuery ajax
>>> serializeThisWithHidden;
>>> script: [ :s | s << (((s jQuery
>>> expression:(JSStream on: 'myself')) closest: 'tr') html: self report)
>>> ]))
>>> asFunction apply: #());
>>>
>>> The idea is to generate this:
>>>
>>> onclick = "(function(){ var myself = this; <
> <ajax call>
>> })()"
>>>
>>> The above might or might not work because I did not try it. But
>>> something
>>> along those lines should work...
>>>
>>>
>> mmmm this is what get's generated:
>>
>> function(){var myself =
>> this;jQuery.ajax({"url":"/MyApp","data":["_s=w9GmvDOQpAp_pp0c","_k=-3MfxH3kyGWxn6Vi","96",jQuery(this).next("input:hidden").andSelf().serialize()].join("&"),"dataType":"script"})}()
>>
>> I don't see 'myself' used it later....
>>
>> BTW, in your example you do: "html: self report". but...since in this
>> case
>> I am re-rendering the row only (and not the whole table/report), I should
>> only re-render the row right? so I should do something like instead:
>>
>> self renderRowOfObject: anObject with: html ?
>>
>> and there write the row
>>
>> Thanks for you help Johan.
>>
>>
>> Johan_______________________________________________
>>> seaside mailing list
>>>
> seaside at .squeakfoundation
>>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>>>
>>
>>
>>
>> --
>> Mariano
>> http://marianopeck.wordpress.com
>>
>
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
> _______________________________________________
> seaside mailing list
> seaside at .squeakfoundation
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
--
View this message in context: http://forum.world.st/Checkbox-and-AJAX-tp4731692p4766672.html
Sent from the Seaside General mailing list archive at Nabble.com.
More information about the seaside
mailing list