> If I wanted to use formlib to build the form, and wanted to build a HTML 
> widget for the image field that had a
> file input for uploading, and if img already had content woudl display a 
> thumbnail; how would I go about this? I'm afraid I'm lost because its 
> schema.Object that the widget would apply to (but I'm not sure).

In such case, I use custom widget.

from zope.app.form.browser.textwidgets import FileWidget
from zope.app.file.image import Image
class MyImageWidget(FileWidget):
  class_ = Image
  def _toFieldValue(self, input):
    value = super(_toFieldValue, self)._toFieldValue(input)
    return self.class_(value)

from zope.formlib import form
class MyEditForm(form.PageEditForm):
  form_fields = form.FormFields(IMyContent)
  form_fields['image'].custom_widget = MyImageWidget

And there is widget subdirective in addform/editform directives in zcml.

Tahara Yusei
Zope3-users mailing list

Reply via email to