Dynamically adding children

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

Dynamically adding children

François Beausoleil-4
Hi all !

I'm still learning my way around Smalltalk / Seaside.  I have the
regular Address Book application running.  I have Name, Address, Phone
and Contact model objects.  I have corresponding *Editor classes too.

I can edit objects which already have addresses, and now I'm ready to
tackle adding new addresses from the UI.

A Contact has many Addresses, and Contact sports these methods to access them:
#addresses
#addressAt:
#addressAt:put:

What I want to achieve is on the contact editor form, I want a place
where I can type the name/location of the new address, and after
submitting the form, a new, blank, AddressEditor should be appended to
the general form.

Here is my incomplete solution:

html form: [
        html fieldsetWithLegend: 'Contact' do: [
        html render: nameEditor.
        html divNamed: 'addresses' with: [
                html label: 'New address named' input: [
                html textInputWithCallback: [:name |
                        self model addressAt: name put: Address new.
                        subcomponents add: (self addressEditorFor: (self model addressAt:
name) named: name)].
                html submitButton.
                addressEditors keysAndValuesDo: [:location :editor |
                        html divClass: 'address' with:  [html render: editor]]]].
        html submitButtonWithAction: [self save]]]

I don't even know if it's valid to change subcomponents (which is
returned by #children) while callbacks are being processed.  I found a
thread[1] which explained a similar problem, except the OP was doing
it with live updates.  I'm not ready for that yet.

Anyway, it's probably something simple, and I'm not finding it.  I
must also be using the wrong query in GMail, because I can't find
anything remotely resembling what I want.

Thanks !
--
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/

[1] http://lists.squeakfoundation.org/pipermail/seaside/2006-July/008377.html

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

Re: Dynamically adding children

Philippe Marschall
2006/10/3, Francois Beausoleil <[hidden email]>:

> Hi all !
>
> I'm still learning my way around Smalltalk / Seaside.  I have the
> regular Address Book application running.  I have Name, Address, Phone
> and Contact model objects.  I have corresponding *Editor classes too.
>
> I can edit objects which already have addresses, and now I'm ready to
> tackle adding new addresses from the UI.
>
> A Contact has many Addresses, and Contact sports these methods to access them:
> #addresses
> #addressAt:
> #addressAt:put:
>
> What I want to achieve is on the contact editor form, I want a place
> where I can type the name/location of the new address, and after
> submitting the form, a new, blank, AddressEditor should be appended to
> the general form.
>
> Here is my incomplete solution:
>
> html form: [
>         html fieldsetWithLegend: 'Contact' do: [
>         html render: nameEditor.
>         html divNamed: 'addresses' with: [
>                 html label: 'New address named' input: [
>                 html textInputWithCallback: [:name |
>                         self model addressAt: name put: Address new.
>                         subcomponents add: (self addressEditorFor: (self model addressAt:
> name) named: name)].
>                 html submitButton.
>                 addressEditors keysAndValuesDo: [:location :editor |
>                         html divClass: 'address' with:  [html render: editor]]]].
>         html submitButtonWithAction: [self save]]]
>
> I don't even know if it's valid to change subcomponents (which is
> returned by #children) while callbacks are being processed.  I found a
> thread[1] which explained a similar problem, except the OP was doing
> it with live updates.  I'm not ready for that yet.
>
> Anyway, it's probably something simple, and I'm not finding it.  I
> must also be using the wrong query in GMail, because I can't find
> anything remotely resembling what I want.

Yes this is valid. Just make sure you backtrack the component you add
the childeren to. The simplest way to do this is add:

self session registerObjectForBacktracking: self

in the initialize method of the component.

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

Re: Dynamically adding children

François Beausoleil-4
Hello Philippe,

2006/10/3, Philippe Marschall <[hidden email]>:
> self session registerObjectForBacktracking: self

Thanks for your help.  I finally had time to try it again, with
backtracking.  Unfortunately, it doesn't work either.  After I click
the submit button to add a new address, the view redisplays, but I
don't get the expected address editor.

If I start a new session and visit the contact, the new address IS added.

For reference, here is part of my #renderContentOn again:
html label: 'New address named' input: [
html textInputWithCallback: [:name |
        self model addressAt: name put: Address new.
        subcomponents add: (self addressEditorFor: (self model addressAt:
name) named: name)].
html submitButton.

I am really at a loss as to what I should do here.

Thanks !
--
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/

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

Re: Dynamically adding children

Philippe Marschall
Hi

Well without further information it is hard to tell more. See the
attached minimal demo.

Philippe

2006/10/5, Francois Beausoleil <[hidden email]>:

> Hello Philippe,
>
> 2006/10/3, Philippe Marschall <[hidden email]>:
> > self session registerObjectForBacktracking: self
>
> Thanks for your help.  I finally had time to try it again, with
> backtracking.  Unfortunately, it doesn't work either.  After I click
> the submit button to add a new address, the view redisplays, but I
> don't get the expected address editor.
>
> If I start a new session and visit the contact, the new address IS added.
>
> For reference, here is part of my #renderContentOn again:
> html label: 'New address named' input: [
> html textInputWithCallback: [:name |
>         self model addressAt: name put: Address new.
>         subcomponents add: (self addressEditorFor: (self model addressAt:
> name) named: name)].
> html submitButton.
>
> I am really at a loss as to what I should do here.
>
> Thanks !
> --
> François Beausoleil
> http://blog.teksol.info/
> http://piston.rubyforge.org/
>
> _______________________________________________
> 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

Children-pmm.1.mcz (1K) Download Attachment