I want to dynamically assign a widget to a RichTextField
depending on its mimeType
.
I have the following questions:
- should I do it in the
updateWidgets
or in theupdate
method of the form? - is it right to check if the field is a RichTextField with
self.fields['my_richtext'].field.schema.__identifier__ == 'plone.app.textfield.interfaces.IRichTextValue'
or is there a better way? - how do I get the
mimeType
of the field/widget/value?
def updateWidgets(self, prefix=None):
super(EditForm, self).updateWidgets()
if self.fields['my_richtext'].field.schema.__identifier__ \
== 'plone.app.textfield.interfaces.IRichTextValue':
# check here the "mimeType":
self.fields["my_richtext"].widgetFactory = MyFieldWidget
z3c.form.form.Form.updateWidgets(self)