Fork of plone.formwidget.contenttree
This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
Go to file
Gaudenz Steinlin f6d79e8b94 Ignore missing values
Content objects can go away or the content of a source may change. Don't
throw an exception in this case.
2013-06-06 15:35:09 +02:00
docs Ignore missing values 2013-06-06 15:35:09 +02:00
plone Ignore missing values 2013-06-06 15:35:09 +02:00
.gitignore Update gitignore file 2013-03-12 19:24:49 +01:00
.travis.yml Update travis file 2013-03-12 20:41:16 +01:00
MANIFEST.in recursive-include docs in MANIFEST.in 2012-03-06 22:04:23 +01:00
README.txt Remove tabs in README.txt 2013-03-12 11:02:08 +01:00
bootstrap.py Add buildout 2013-03-12 19:24:18 +01:00
buildout.cfg Add buildout 2013-03-12 19:24:18 +01:00
jenkins.cfg Add jenkins config 2013-03-12 19:24:42 +01:00
setup.cfg Initial checkin 2008-08-31 23:57:55 +00:00
setup.py Switch to plone.app.testing 2013-03-12 20:06:35 +01:00
test-plone-4.3.x.cfg Switch to plone.app.testing 2013-03-12 20:06:35 +01:00
travis.cfg Get travis to test against Plone 4.3rc1. 2013-03-12 22:31:39 +01:00

README.txt

Introduction
============

plone.formwidget.contenttree is a z3c.form widget for use with Plone. It
uses the jQuery Autocomplete widget, and has graceful fallback for non-
Javascript browsers.

There is a single-select version (AutocompleteSelectionFieldWidget) for
Choice fields, and a multi-select one (AutocompleteMultiSelectionFieldWidget)
for collection fields (e.g. List, Tuple) with a value_type of Choice.

When using this widget, the vocabulary/source has to provide the IQuerySource
interface from z3c.formwidget.query and have a search() method.

Example Usage::

    from zope.component import adapts
    from zope.interface import Interface, implements
    from zope import schema

    from plone.z3cform import layout

    from z3c.form import form, button, field

    from plone.formwidget.contenttree import ContentTreeFieldWidget
    from plone.formwidget.contenttree import MultiContentTreeFieldWidget
    from plone.formwidget.contenttree import PathSourceBinder


    class ITestForm(Interface):

        buddy = schema.Choice(title=u"Buddy object",
                              description=u"Select one, please",
                              source=PathSourceBinder(portal_type='Document'))

        friends = schema.List(
            title=u"Friend objects",
            description=u"Select as many as you want",
            value_type=schema.Choice(
                title=u"Selection",
                source=PathSourceBinder(portal_type='Document')))


    class TestAdapter(object):
        implements(ITestForm)
        adapts(Interface)

        def __init__(self, context):
            self.context = context

        def _get_buddy(self):
            return None
        def _set_buddy(self, value):
            print "setting", value
        buddy = property(_get_buddy, _set_buddy)

        def _get_friends(self):
            return []
        def _set_friends(self, value):
            print "setting", value
        friends = property(_get_friends, _set_friends)


    class TestForm(form.Form):
        fields = field.Fields(ITestForm)
        fields['buddy'].widgetFactory = ContentTreeFieldWidget
        fields['friends'].widgetFactory = MultiContentTreeFieldWidget
        # To check display mode still works, uncomment this and hit refresh.
        #mode = 'display'

        @button.buttonAndHandler(u'Ok')
        def handle_ok(self, action):
            data, errors = self.extractData()
            print data, errors

    TestView = layout.wrap_form(TestForm)