VisualWidget, don't do It

More accurately, can't do it. A schema for Archetypes Visual Widget that works.

Archetypes Visual widget - the WYSIWYG HTML editor that shows up on Pages in Plone 2.5 - is pretty damn nice. I've had problems with Epoz and this is the first embedded web editor that makes me think about giving up on restructured text.

Getting it to work in your own classes is another issue.

I had an Archetypes defined class (part of the ReLaIS project) that I thought would look nice with one of those rich HTML fields in it. Try as I might, I couldn't get it work. The widget would appear in editting mode, but spew out plain text at viewing. I'd fiddle with the schema and then the widget would appear as a plain text area in editing but produce valid HTML. There were almost no examples on the web of successful use. Finally, I systematically deleted and added fields to the schema until I found what worked:

TextField ('body',
        default_output_type='text/x-html',
        allowable_content_types=(
                'text/plain',
                'text/structured',
                'text/html',
        ),
        widget=VisualWidget (
                label="Body",
                rows=30,
                description="Some text or explanation before the form",
        ),
),

The magic lines would appear to be default_output_type and allowable_content_types. Don't use default_content_type, it won't make you happy.

Other points: the parent Field has to be a TextField. StringFields won't do. The default_output_type can also be text/x-html-safe (for filtered HTML). I also have a suspicion - from some odd bugs - that only one VisualWidget can exist on any one page. Caveat programmer.

Technical details

Zope 2.94, Plone 2.1.4, Archetypes 1.4.1. Brownie points if you caught the "Heathers" reference.