Setting pattern_options in a Plone relation field widget

To use the full power of the RelationWidget in Plone 5, you can set some of the pattern_options, which are described in the link Mockup docs.

If you use a ReleationField, you usually want to browse thru all objects in the database, but only allow to select specific portal_types.

The pattern relateditems which is used by the RelatedItemsFieldWidget, has options to configure this by setting the selectableTypes list (array).

You can pass the patter_options argument to the widget configuration, with plone.autoform.directives like this:

directives.widget(
    'location',
    RelatedItemsFieldWidget,
    pattern_options={'selectableTypes': ['location']},
)
locations = RelationList(
    title=_(u'Locations'),
    value_type=RelationChoice(
        title=_(u'Related'),
        source=CatalogSource(),
    ),
    required=False,
)

This will update the pattern_options with your provided config.

The same way you can add more confgiuration settings for the pattern, like the basePath for example.

By @MrTango in
Tags :