On Jun 7, 2011, at 9:08 PM, Noah Davis wrote:

> 
> 
> On Jun 7, 2:55 pm, "Diez B. Roggisch" <[email protected]> wrote:
>>> I've got a pair of tw.forms that are children of a custom widget. All
>>> the widgets are named, so the resulting fields have names like
>>> "person_form.firstname", etc. I can pass data to the forms at
>>> instantiation time (although using unqualified names like "firstname",
>> 
>> This sounds suspicious. What do you mean by instantiation time?
>> 
> 
> Sorry, in the template itself, not when the widget is actually
> instantiated. The widget is passed to the template through
> templ_context, which I understand is the current accepted method for
> non-data objects. In the template the widget is realized like
> tmpl_context.my_compound(dict(person_form=dict(firstname=firstname...
> etc.

Ok, that's after the book.



>>> rather than "person_form.firstname"), but the kwargs dict passed to
>>> the controller contains keys as "person_form.firstname", etc.
>> 
>>> This isn't a problem, although it seems a little counter intuitive,
>>> until I add validators... at which time the validators begin to fail
>>> with errors like "The input field 'person_form' was not expected.",
>>> which I suspect is directly related to the name mangling going on with
>>> the child/parent widget relationships.
>> 
>> How exactly do you add validators to the mix?
> 
> class PersonForm(TableForm):
>    show_error = True
>    fields = [
>        TextField('firstname', validator=NotEmpty, label_text='First
> Name:', show_error=True),
>        TextField('lastname', validator=NotEmpty(msg="test"),
> label_text='Last Name:'),
>        TextField('phone', validator=NotEmpty, label_text='Phone:'),
> #FIXME: Validator for Phone
>        HiddenField('method'),
>        HiddenField('term'),
>        ]
>    submit_text='Add Person'
> 
> Then add @validate(form=pform, error_handler=...) to the appropriate
> controller methods.

Hm. Try adding a strip_name=True to the encompassing widget. Or a 
strip_name=False to the form.

 It looks a bit though as if there is some incongruency here, between how forms 
are renderend (and what value-structure they assume), and the validator 
structure. Might in fact be a bug. If I find time, I take a look into it.

Diez

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