[Zope3-Users] trying to create an ObjectWidget for z3c.form

Christophe Combelles ccomb at free.fr
Sun Dec 9 18:47:00 EST 2007


Martijn Faassen a écrit :
> Hey,
> 
> On Dec 7, 2007 1:54 PM, Christophe Combelles <ccomb at free.fr> wrote:
> [snip]
>> 2- Then I'm trying to create a form for a single Object field. I've understood
>> that this case should be handled by a subform. So I could create such a thing by
>> using a template for the main form, and a subtemplate for the subform. But then,
>> I've begun using z3c.formui to have a better template for the main form, but now
>> how do I display the subform in the div-based formui template?
>>
>> The real final thing I'm trying to do is just a form for a
>> List(value_type=Object(schema=IStuff),
>> with IStuff being just  made of 3 TextLine fields.
>> Doing this is quite easy with the formlib, or maybe I got used to it, but I'd
>> really like to be able to do all the same things with z3c.form
> 
> Just so you know I really look for such features too. z3c.form simply
> declares that subforms are the way to go,
> but when I look at example code I see rather involved ways information
> has to pass back and forth between subform
> and form. I hope more automation is possible here, while hopefully
> retaining the increased control that z3c.form offers. Something
> like an object widget that lets you specify a sub-form and template
> manually. I looked at z3c.form to find such increased control for one
> project, but the lack of automation really killed that for this
> particular case.


I've begun implementing an ObjectWidget today for z3c.form.
I wanted to finish it to be able to use it in a small contracted project, but it 
seems it will take more time, and I'm in a real emergency so I reverted back my 
project to a classical formlib/BrowserPage/macros layout to be able to deliver 
it in time. However, I will work on it again by the end of the week.

You can already take a look at it here
http://svn.zope.org/Sandbox/ccomb/z3c.form/trunk/

I've tried to follow Stephan's advice, which is using a subform.

My idea is the following: since widgets already are IFormAware, which means they 
can access the parentform through a 'form' attribute', I have added another 
interface ISubformAware that offers a 'subform' attribute just for the ObjectWidget.

The 'subform' attribute allows the objectwidget to remember the subform it is 
associated to, but the subform is initially stored in the form under the same 
name as the field, just like it is done in the subform example. So I might 
expect it to be backward compatible.
The subform is created automatically during the update() of the widget,
and a template of the objectwidget can easily loop over the subform with 
tal:repeat="widget view/subform/widgets/values" to render the widgets.

The doctest is already working for a simple addform, but it is incomplete, and I 
don't know where, when and how to create the associated object. The user should 
probably provide a factory, just as with the formlib.

comments and ideas are welcome

Christophe

> 
> Regards,
> 
> Martijn
> 
> 



More information about the Zope3-users mailing list