jquery serialization question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

jquery serialization question

larrry
Hi,

I'm having some strange problem with Jquery/Seaside.

I'm trying to serialize a form containing a single testArea when the
submit button is clicked. I have an onClick handler for the submit
button that does this:

(html jQuery ajax serializeForm
                                                onSuccess:
                                                        (html jQuery ajax
                                                                script: [ :s |
                                                                        s add: ((html jQuery: #postStatusTextArea) value: '').
                                                                        s add: ((html jQuery: #activityStream) prepend:
(CBActivityComponent post: self session user posts first)) ]) );

If I execute this by clicking the button the callback for the textArea
gets invoked twice most of the time (though not every time).

I tried wrapping the same logic inside a block instead of parens like so:

[html jQuery ajax serializeForm
                                                onSuccess:
                                                        (html jQuery ajax
                                                                script: [ :s |
                                                                        s add: ((html jQuery: #postStatusTextArea) value: '').
                                                                        s add: ((html jQuery: #activityStream) prepend:
(CBActivityComponent post: self session user posts first)) ]) ];

Now it submits exactly once every time. However, other javascript
functionality on the pages stops working.

So my questions are, should the onClick be inside a block as in the
second example, and if not, does anyone have any idea why the
non-block version would serialize twice per click (some of the time).

thanks much.

Larry
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: jquery serialization question

Bob Arning
Probably wouldn't hurt to offer more detail, but here is a runnable version of your snippet that seems to happen once per click.

renderContentOnLarry1: html
   
    | fromCallback counter |
   
    counter _ 0.
    html form: [
        html textArea
            id: #postStatusTextArea;
            callback: [ :value | counter _ counter + 1. fromCallback _ value.];
            value: 'initial text'.
        html div
            onClick: (html jQuery ajax serializeForm
                onSuccess:
                    (html jQuery ajax
                        script: [ :s |
                            s add: ((html jQuery: #postStatusTextArea) value: counter asString,' [',fromCallback asString,']').
                            s add: ((html jQuery: #activityStream) prepend: counter asString) ]) );
            with: 'click here'
    ]

My guess would be that you used a submitButton that forced a serialization/callback in addition to the explicit one you included.

Cheers,
Bob


On 10/16/11 9:43 AM, Larry White wrote:
Hi,

I'm having some strange problem with Jquery/Seaside.

I'm trying to serialize a form containing a single testArea when the
submit button is clicked. I have an onClick handler for the submit
button that does this:

(html jQuery ajax serializeForm
						onSuccess:
							(html jQuery ajax
								script: [ :s |
									s add: ((html jQuery: #postStatusTextArea) value: '').
									s add: ((html jQuery: #activityStream) prepend:
(CBActivityComponent post: self session user posts first)) ]) );

If I execute this by clicking the button the callback for the textArea
gets invoked twice most of the time (though not every time).

I tried wrapping the same logic inside a block instead of parens like so:

[html jQuery ajax serializeForm
						onSuccess:
							(html jQuery ajax
								script: [ :s |
									s add: ((html jQuery: #postStatusTextArea) value: '').
									s add: ((html jQuery: #activityStream) prepend:
(CBActivityComponent post: self session user posts first)) ]) ];

Now it submits exactly once every time. However, other javascript
functionality on the pages stops working.

So my questions are, should the onClick be inside a block as in the
second example, and if not, does anyone have any idea why the
non-block version would serialize twice per click (some of the time).

thanks much.

Larry
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: jquery serialization question

Lukas Renggli
In reply to this post by larrry
> I'm trying to serialize a form containing a single testArea when the
> submit button is clicked. I have an onClick handler for the submit
> button that does this:
>
> (html jQuery ajax serializeForm
>                                                onSuccess:
>                                                        (html jQuery ajax
>                                                                script: [ :s |
>                                                                        s add: ((html jQuery: #postStatusTextArea) value: '').
>                                                                        s add: ((html jQuery: #activityStream) prepend:
> (CBActivityComponent post: self session user posts first)) ]) );

- There is a cascade semicolon missing after #serializeForm, but it
probably doesn't matter much.

- You likely want to return false to the click handler, otherwise a
full submit will be triggered. You can do this by adding

      (html jQuery ajax
          serializeForm;
          onSuccess: ...;
          return: false)

> If I execute this by clicking the button the callback for the textArea
> gets invoked twice most of the time (though not every time).

If the AJAX call is faster you get the AJAX submit, then a full submit.

If the full submit is faster, the AJAX call is cancelled by the
browser and you get only one submit.

Lukas

--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: jquery serialization question

larrry
Thanks guys. That was it!

Sent from my iPhone

On Oct 16, 2011, at 10:35 AM, Lukas Renggli <[hidden email]> wrote:

>> I'm trying to serialize a form containing a single testArea when the
>> submit button is clicked. I have an onClick handler for the submit
>> button that does this:
>>
>> (html jQuery ajax serializeForm
>>                                                onSuccess:
>>                                                        (html jQuery ajax
>>                                                                script: [ :s |
>>                                                                        s add: ((html jQuery: #postStatusTextArea) value: '').
>>                                                                        s add: ((html jQuery: #activityStream) prepend:
>> (CBActivityComponent post: self session user posts first)) ]) );
>
> - There is a cascade semicolon missing after #serializeForm, but it
> probably doesn't matter much.
>
> - You likely want to return false to the click handler, otherwise a
> full submit will be triggered. You can do this by adding
>
>      (html jQuery ajax
>          serializeForm;
>          onSuccess: ...;
>          return: false)
>
>> If I execute this by clicking the button the callback for the textArea
>> gets invoked twice most of the time (though not every time).
>
> If the AJAX call is faster you get the AJAX submit, then a full submit.
>
> If the full submit is faster, the AJAX call is cancelled by the
> browser and you get only one submit.
>
> Lukas
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside