DEV Community

Maik Derstappen
Maik Derstappen

Posted on • Originally published at mrtango.planetcrazy.de on

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,
)

Enter fullscreen mode Exit fullscreen mode

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.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay