[Zope3-Users] AW: z3c.form and subforms in an AddForm?
Mats Nordgren
mats at ronin-group.org
Sun Jun 17 17:17:12 EDT 2007
Roger,
Thanks for your reply. I'm still having problems getting this to work.
I'm not sure I am supposed to use a BaseForm, Form, AddForm, or what, for
the sub-item. I'm not sure how to register it in zcml to not get adaption
errors when I run it.
Would there be any chance to have the example with the "car" and "owner" in
the Sub-Form doc test included in the formdemo package. I'd like to see
that included with "Class I" and "Class II" for both AddForm and EditForm
since it is such a common use case.
Perhaps I'm just dense, but I still have problems converting doc tests into
an actual working zope instance. The formdemo package was a god send to get
a simple addform working since I had no idea you needed to use the
IFormLayer. Using the demo that was no longer a problem.
Again thanks for all your help.
Mats Nordgren
> Hi
>
>> Betreff: [Zope3-Users] z3c.form and subforms in an AddForm?
>>
>>
>> I've been trying out the new z3c form package and like what I
>> see. I am having problems getting a subform in an AddForm
>> though. The subform.txt covers EditForms where you have a
>> context object to work on, in an AddForm the context is the
>> underlying IContainer.
>>
>> Here is what I have, using formdemo examples as the basis.
>> Any help on getting this to work is greatly appreciated.
>>
>> IRestaurant with address attribute using schema.Object
>> holding an IAddress.
>>
>> browser/restaurant.py
>>
>> class RestaurantAddForm(AddFormLayoutSupport, form.AddForm):
>> """Add form"""
>>
>> template = None
>> layout = None
>> contentName = None
>> label = u'Add Restaurant'
>>
>> fields = field.Fields(IRestaurant).omit('address')
>>
>> def update(self):
>> self.address = AddressAddForm(self.context.address,
>> self.request) ##
>> <---- Problem area
>> self.address.update()
>> super(RestaurantAddForm, self).update()
>
> You can add a custom setupWidgets method in the sub form which
> disables the context adaption.
>
> Stephan and I duscussed this during development, I think we
> should add the hook into the form. He thinks not. But I guess
> we have to discuss this once again.
>
> Here is the method for context less forms:
>
> def updateWidgets(self):
> self.widgets = zope.component.getMultiAdapter(
> (self, self.request, self.getContent()), interfaces.IWidgets)
> self.widgets.ignoreContext = True
> self.widgets.ignoreReadonly = True
> self.widgets.update()
>
>
>> def create(self, data):
>> r = Restaurant()
>> r.name = data['name']
>> r.description = data['description']
>> r.address = data['address']
>> return r
>>
>> def add(self, object):
>> self._name = object.name
>> self.context[self._name] = object
>> return object
>>
>> def nextURL(self):
>> return absoluteURL(self.context[self._name], self.request)
>
>
> Regards
> Roger Ineichen
--
View this message in context: http://www.nabble.com/z3c.form-and-subforms-in-an-AddForm--tf3929436.html#a11167050
Sent from the Zope3 - users mailing list archive at Nabble.com.
More information about the Zope3-users
mailing list