I see,
I have always been used at wrapping forms in a div with id even in
TW1, so I never found this issue before.

I think it is probably a tw2 bug as the right behavior is the one you
get when you don't specify the id.
The id of the root element should probably not be added to the field names.

About the fieldset behavior, that is the expected one. If I'm not
wrong, It was like that also on TW1.
To unpack the arguments you just have to add @validate(MovieForm) to
your index controllers and it will receive the arguments in nested
dictionaries instead of multiple arguments separated by colon.

Adding @validate should fix also the behavior with ID as it will
unpack those too.

On Thu, Jun 21, 2012 at 1:34 PM, Christoph Zwerschke <[email protected]> wrote:
> Am 21.06.2012 10:45, schrieb Alessandro Molina:
>
>> If you can provide a minimal example that shows your issue and how you
>> would expect the parameters to be passed I'll be more than glad to
>> give it a try. I didn't yet have to play with nested widgets in tw2,
>> so I'm more than happy to have a reason to do it :)
>
>
> Just take the example from our TW tutorial:
>
> from tw2.forms import *
>
> class MovieForm(TableForm):
>
>    id = 'movieform'
>    title = TextField()
>    year = TextField()
>    release_date = CalendarDatePicker()
>    genre_options = [x for x in enumerate((
>        'Action & Adventure', 'Animation', 'Comedy',
>        'Documentary', 'Drama', 'Sci-Fi & Fantasy'))]
>    genre = SingleSelectField(options=genre_options)
>    description = TextArea()
>
> Add this line to the controller:
>
> tmpl_context.form = MovieForm()
>
> Add this line to the page template:
>
> <div py:replace="tmpl_context.form.display()"/>
>
> Now if you click the submit button, you get an error such as
>
> TypeError: index() got an unexpected keyword argument
> 'movieform:release_date'
>
> It is one of the niceties of TG that you can receive the values of a form
> through normal Python keyword arguments, but this is not possible if they
> contain a colon.
>
> While writing this post, I found a simple solution: If you remove the id
> parameter from the MovieForm, or smuggle it in using
> attrs=dict(id='movieform'), the name will only consist of the field name
> without the parent name. I had expected that TW2 will add an auto generated
> id anyway, but this is not the case. So for simple forms like the one above
> this should work. If you use fieldsets, you still get the colon problem:
>
> from tw2.core import *
> from tw2.forms import *
>
> class MovieForm(TableForm):
>
>    class child(CompoundWidget):
>        class basic(TableFieldSet):
>            title = TextField()
>            year = TextField()
>        class detail(TableFieldSet):
>            release_date = CalendarDatePicker()
>            genre_options = [x for x in enumerate((
>              'Action & Adventure', 'Animation', 'Comedy',
>              'Documentary', 'Drama', 'Sci-Fi & Fantasy'))]
>            genre = SingleSelectField(options=genre_options)
>            description = TextArea()
>
> In this case, you get 'basic:' and 'detail:' prefixes. I found you can still
> avoid these by adding id=None to the TableFieldSets. Sometimes you don't
> want that (e.g. if you have the same names in different field sets), but
> then, simple keyword arguments wouldn't work anyway.
>
>
> -- Christoph
>
> --
> 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?hl=en.
>

-- 
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?hl=en.

Reply via email to