Ticket #2393 (closed defect: fixed)
Forms with nested schemas
|Reported by:||guest||Owned by:||Chris Arndt|
|Severity:||normal||Keywords:||needs review, forms, FormEncode|
Given a form with schemas (stripped down excerpt below):
class RegistrationForm(ListForm): class RegistrationFields(WidgetsList): class PersonalDetailsFields(WidgetsList): lastname = TextField(label=_(u"Last name")) firstname = TextField(label=_(u"First name")) personal = FieldSet( legend = _(u"Personal information"), fields = PersonalDetailsFields()) class RegistrationSchema(Schema): class PersonalDetailsSchema(Schema): lastname = UnicodeString(strip=True, not_empty=True, max=20) firstname = UnicodeString(strip=True, not_empty=True, max=20) personal = PersonalDetailsSchema() fields = RegistrationFields() validator = RegistrationSchema()
This worked pretty fine with the validate-decorator in TG 1.0.8 using FormEncode 0.7.1. Now with 1.1 (and FormEncode 1.2.2) I always get validate-errors for the schema named PersonalDetailsSchema as there is no such sub-form (the only given sub-form is given by the key 'personal'). Actually the real name would be "personal", like the name of the form above. The @validate-decorator seems to validate the instance of the PersonalDetailsSchema-class as well as the class itself. If I clear out the schema-class by setting PersonalDetailsSchema=None after the instantiation of 'personal' like this:
class RegistrationSchema(Schema): class PersonalDetailsSchema(Schema): lastname = UnicodeString(strip=True, not_empty=True, max=20) firstname = UnicodeString(strip=True, not_empty=True, max=20) personal = PersonalDetailsSchema() PersonalDetailsSchema = None
then validation works well. I can as well move the RegistrationSchema-class out of the RegistrationForm-class to module level, which also works.
I attached a minimal testcase below.
- Owner set to Chris Arndt
- Component changed from TurboGears to TG Widgets
- Milestone changed from __unclassified__ to 1.0.x bugfix