Using WysiwygFieldWidget in a z3c.form form
Question
I'm creating a form with z3c.form and for a textarea, I would like to have a wysiwyg interface.
So I use plone.directives.form to handle that.
In my interfaces.py :
from zope import schema
from plone.directives import form
from plone.app.z3cform.wysiwyg import WysiwygFieldWidget
from zope.i18nmessageid import MessageFactory
_ = MessageFactory('BSWMinisite')
class IMinisiteProperties(form.Schema):
""" """
form.widget(edito=WysiwygFieldWidget)
edito = schema.Text(title = u"Edito",
required=False)
In my content.py :
from plone.directives import form
from z3c.form import button
from Products.CMFPlone import PloneMessageFactory as plMF
from plone.z3cform.layout import wrap_form
from Products.CMFCore.utils import getToolByName
from Products.BSWMinisite.interfaces import IMinisiteProperties
class MinisitePropertiesForm(form.SchemaForm):
""" """
schema = IMinisiteProperties
ignoreContext = True # don't use context to get widget data
@button.buttonAndHandler(plMF('label_save', default=u'Save'), name='apply')
def handleApply(self, action):
""" stuff """
@button.buttonAndHandler(plMF('label_cancel', default=u'Cancel'),
name='cancel')
def handleCancel( self, action):
self.request.RESPONSE.redirect( self.context.absolute_url() )
MinisitePropertiesView = wrap_form(MinisitePropertiesForm)
And in the configure.zcml I have :
<include package="plone.directives.form" file="meta.zcml" />
<include package="plone.directives.form" />
<browser:page
for="*"
name="minisite_properties"
class=".browser.content.MinisitePropertiesView"
permission="cmf.ModifyPortalContent"
/>
When I go to @@minisite_properties I see my field, but no wysiwyg. Do you hnow where I missed something ?
Solution 2
So, the problem was I didn't have the correct version of dexterity, and my package wasn't grok'ed correctly.
In the buildout, to pin the correct dexterity :
extends =
base.cfg
versions.cfg
http://good-py.appspot.com/release/dexterity/1.1?plone=4.1.3
In the main configure.zcml :
<configure xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:grok="http://namespaces.zope.org/grok"
i18n_domain="BSWMinisite">
<!-- Grok the package to initialise schema interfaces and content classes -->
<grok:grok package="." />
<browser:page
for="*"
name="minisite_properties"
class=".browser.content.MinisitePropertiesView"
permission="cmf.ModifyPortalContent"
/>
...
And then in my content.py :
from five import grok
class MinisitePropertiesForm(form.SchemaForm):
""" """
grok.context(IMinisiteProperties)
schema = IMinisiteProperties
OTHER TIPS
Below is my sample code for Dexterity content schema using Dexterity 1.1 pindowns (see Dexterity manual, installation part)
from five import grok
from zope import schema
from plone.directives import form, dexterity
from plone.app.z3cform.wysiwyg import WysiwygFieldWidget
class ICourseInfoContent(form.Schema):
"""
Content page for CourseInfo folders
"""
# Autofilled by course id
title = schema.TextLine(title=u"Title", required=True, default=u"")
# -*- Your Zope schema definitions here ... -*-
form.widget(body=WysiwygFieldWidget)
body = schema.Text(title=u"Body (top)")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow