[Product-Developers] how to set a content-based default value for a field
hink at gw20e.com
Tue Apr 6 15:13:20 UTC 2010
I know how to set a default value for a field, however, i would like this
default value to come from a content item.
The use case: Lots of users are creating content (a custom content-type), but
the site admin would like them to stick to a predefined format. The main
content is in a text-field, and the admin wants some chapters to always be
there, or at least remind their users they should have them in their text. So
the goal is: When someone creates a new MyType object, the chapters (h2
elements) in the 'text' field are filled in already.
Currently, i've defined this in the schema (archetypes), but that requires a
software update if the predefined format should ever change. (Of course, they
don't expect that to happen, ever ;) )
So i'm looking for alternatives. One thing i've tried is to register an event
listener which does a 'setText' on the object (and would later do a catalog
call to fetch the "predefined chapters template" object). However,
Products.Archetypes.interfaces.IObjectInitializedEvent only does something when
an object is saved for the first time, so instead of showing predefined
chapters on the text field in the form, it overwrites the text which was
entered. I've also tried
zope.lifecycleevent.interfaces.IObjectCreatedEvent, which is fired more than
once but does not change the form a user sees.
More information about the Product-Developers