On Sun, Jul 6, 2008 at 12:46 PM, Martin Aspeli <[EMAIL PROTECTED]> wrote: > Hi, > > I'm using z3c.form in Plone via plone.z3cform. The z3c.form documentation is > very good and very detailed, but I must admit to getting a bit lost in all > of it. :) > > To that end, I have a few questions. I'm creating a pair of add- and edit > forms for a content item: > > - I've created a few buttons with @button.buttonAndHandler(). However, I > need to set a different CSS class for each button. What's the easiest way to > do that?
You can override the updateActions method and modify the css after the buttons are created. As you may have read, buttons are like schema fields, and actions are like the widgets for a schema field. So to modify the appearance of a button, you have to actually modify the action: @button.buttonAndHander("My Button", name="myButton") def handleMyButton(self, action): print "handling my button" def updateActions(self): super(MyForm, self).updateActions() self.actions["myButton"].addClass("my-custom-css-class") > - Some fields on the form are provided by the content item. Others can come > from other schemata. There will be adapters from the context to these > interfaces. How do it up so that z3c.form uses the appropriate adapter to > read and write values, including in the add form? In the add form, it is up to you to handle the data input, by implementing the create and add methods. As for the edit forms, I'm not entirely sure about this but I believe the form framework will just do the right thing. i.e. you might say: fields = field.Fields(IMyInterface) fields += field.Fields(IMyOtherInterface) And it will automatically try to adapt the context to the interface from which the field was defined. An alternative way which will definitely work (even if you don't have adapters) is to use groups: class MyOtherInterfaceGroup(group.Group): fields = field.Fields(IMyOtherInterface) def getContent(self): # do whatever you have to do to get something implementing IMyOtherInterface, adaptation or otherwise return myInterfaceToOtherInterfaceAdapter(self.context) #even a direct call to a specific adapter class MyForm(group.GroupForm): fields = field.Fields(IMyOtherInterface) groups = (MyOtherInterfaceGroup,) This is essentially the poor man's version of having a subform. It's also a great way to fake "object widgets" when one of the fields of IMyInterface is of type zope.schema.Object. > - I'd like to group widgets together into fieldsets. A fieldset may contain > widgets from multiple interfaces. All fieldsets will be on the same form, in > different <fieldset /> tags. Should I look to use groups for this? Subforms? > Or something else? I'd recommend just writing your own template. I've found that the templates in z3c.formui can only take you so far, and are best used as prototyping tools and reference documents. Of course, you can always reuse many of the macros, especially when it comes to displaying widget error messages. -- Paul Carduner http://www.carduner.net _______________________________________________ Zope3-users mailing list Zope3email@example.com http://mail.zope.org/mailman/listinfo/zope3-users