On 11/05/2006, at 18:43, mulicheng wrote:

>
> Interesting, at this point, I just put the form on my template for the
> page.  I suppose that doesn't work very well for Re-Use if I want to
> use the form somewhere else again though.
>
> I do have a case where I have a Billing and Shipping Address that  
> might
> be possible to be re-used.  Would it be possible to create a Form that
> is simply an address and then nest two of those widgets inside another
> form?  There would have to be a way to not require all of the shipping
> address fields if the user checks a box stating that the addresses are
> the same.  I've seen a little conversation on the list about nested
> values/forms but it isn't very clear how one would set something like
> that up.

You're definetily getting it... ;) Yep, this is the whole point about  
widgets... easier reuse.

You can't actually nest a form inside another form, well, maybe you  
can, but I'm 99% sure most browser will scream. You can, however,  
factor out complex related fields into a compound widget you can reuse.

Take a look at AutoCompleteField, which is a compound field with two  
child fields: a hidden 'id' and the text you see.

Or at this selectshuttle (soon to be merged with Godoys) http:// 
tinyurl.com/kanw5. This one has a handful of hidden fields for all  
the data the javascript can provide

If you're needs are not very sophisticated, maybe a plain ol'  
Fieldset will serve you best.

One *important* thing to note regarding compound input fields (Form,  
Fieldset, etc), they will submit a *dict* to your controller:

class MyForm(Form):
        fields = [
                TextName("name"),
                FieldSet("data", fields=[
                        TextField("foo", validator=Int()),
                        TextField("bar"),
                ]
        ]

@validate(form=MyForm())
@expose()
def process_form(self, name, data):
        assert isinstance(name, basestring)
        assert isinstance(data, dict)
        assert isinstance(data['foo'], int)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to