Form.Element.Observer / Callback mix-up?

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

Form.Element.Observer / Callback mix-up?

Ken Treis
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.

Thanks,

--
Ken Treis
Miriam Technologies, Inc.

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

Re: Form.Element.Observer / Callback mix-up?

Lukas Renggli
> 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.

Your problem has to do with the order and the way in which Seaside
evaluates callbacks.

The first thing to notice is that it doesn't make much sense (and is
not even supported by Seaside) to trigger submit-buttons from AJAX
actions. Your code works if you remove the button from the form or
instead trigger the two form elements independently without including
the button.

> 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.

I am working on this.

Lukas

--
Lukas Renggli
http://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: Form.Element.Observer / Callback mix-up?

Lukas Renggli
The latest version of Seaside2.8/Scriptaculous fixes your problem (it
doesn't matter anymore where you put the script):

-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-

Name: Seaside2.8a1-lr.431
Author: lr
Time: 8 August 2007, 2:53:13 pm
UUID: 47c945ed-d9dc-4861-bb0d-54dd9a5cdea6
Ancestors: Seaside2.8a1-pmm.430

- don't signal the render notification for action callbacks in ajax request
- fixed WAButtonTag and WAButtonTest

-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-

Name: Scriptaculous-lr.207
Author: lr
Time: 8 August 2007, 3:16:25 pm
UUID: f0175d4c-c25c-483f-92f9-d89963f260ce
Ancestors: Scriptaculous-lr.206

- added some more comments
- fixed the drag & drop tests so that it works without sushi store loaded
- SUAjax uses its own kind of callbacks now
- Added event registration to elements
- Made SUIfThenElse an expression (not a statement anymore)

-=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-

Next thing is making Form.Element.Observer an object ;-)

Lukas

--
Lukas Renggli
http://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: Form.Element.Observer / Callback mix-up?

Ken Treis
Thank you Lukas. I appreciate the explanations and the quick fix.

When I have done this sort of thing in Rails, I never noticed that  
the submit buttons were included in the form data. The URLs for form  
submission and AJAX submission were always different, so it didn't  
matter.

Callbacks make AJAX so much cleaner... I love it.


Ken

On Aug 8, 2007, at 6:24 AM, Lukas Renggli wrote:

> The latest version of Seaside2.8/Scriptaculous fixes your problem (it
> doesn't matter anymore where you put the script):
>
> -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-  
> -=- -=-
>
> Name: Seaside2.8a1-lr.431
> Author: lr
> Time: 8 August 2007, 2:53:13 pm
> UUID: 47c945ed-d9dc-4861-bb0d-54dd9a5cdea6
> Ancestors: Seaside2.8a1-pmm.430
>
> - don't signal the render notification for action callbacks in ajax  
> request
> - fixed WAButtonTag and WAButtonTest
>
> -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-  
> -=- -=-
>
> Name: Scriptaculous-lr.207
> Author: lr
> Time: 8 August 2007, 3:16:25 pm
> UUID: f0175d4c-c25c-483f-92f9-d89963f260ce
> Ancestors: Scriptaculous-lr.206
>
> - added some more comments
> - fixed the drag & drop tests so that it works without sushi store  
> loaded
> - SUAjax uses its own kind of callbacks now
> - Added event registration to elements
> - Made SUIfThenElse an expression (not a statement anymore)
>
> -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=- -=-  
> -=- -=-
>
> Next thing is making Form.Element.Observer an object ;-)
>
> Lukas
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
> _______________________________________________
> Seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

--
Ken Treis
Miriam Technologies, Inc.

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

Re: Form.Element.Observer / Callback mix-up?

Lukas Renggli
> When I have done this sort of thing in Rails, I never noticed that
> the submit buttons were included in the form data. The URLs for form
> submission and AJAX submission were always different, so it didn't
> matter.

Good to know. We should probably do the same and ignore buttons with
AJAX callbacks altogether. Anybody objects?

Cheers,
Lukas

--
Lukas Renggli
http://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: Form.Element.Observer / Callback mix-up?

Sebastian Sastre-2

> Good to know. We should probably do the same and ignore
> buttons with AJAX callbacks altogether. Anybody objects?
>
> Cheers,
> Lukas
>
A warning in the transcript instead of a silent ingnore could be friendlier
and educative

Cheers,

Sebastian

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