Widget parameter for CatalogSource based ChoiceField


on plone 5.2 i have a custom content-type with a shema on the filesystem.

I want to get the widget for a plone.app.vocabularies.catalog.CatalogSource based Choice-Field working. It displays a loading error. Maybe i am missing some widget-parameter in the shema definition, but cannot find any documentation about setting it.

I found the great section 34.1 in the 34. Dexterity: Reference – Mastering Plone 5 development — Plone Training 2023 documentation, but unfortunately there is no example with a choice field using a CatalogSource.

There are examples on setting widget parameters on a RelationCoice-fields. But which of them if any can be used or which are needed for a ChoiceField with a select2-widget ?

Maybe it's wrong that a select2-widget is the default for a CatalogSource-based Coice-Field and i should use a simple dropdown like in the level1-field ?


Thats what i do in Plone 6, but it should work in Plone 5.

def basePath(context=None):
    folder = contact_persons_folder()
    if not folder:
        folder = api.portal.get()

    return "/".join(folder.getPhysicalPath())

class IContactPersonBehavior(model.Schema):
    contacts = schema.List(
        title=_("Contactpersons / Business Card"),
            "add information for directly contact, if the contact not exists, please add <a href='${add_contact_person_url}' target='_blank'>here the new Contact</a>",
            mapping={"add_contact_person_url": add_contact_person_url_factory()},
            title=_("Contact Person"),
            description=_("Select the right Contact Person"),

            "selectableTypes": ["Contact Person"],
            "favorites": False,
            "recentlyUsed": True,
            "basePath": basePath,

I thought I remembered having used a CatalogSource to achieve what you want (Plone 5.2). As it turns out, I eventually gave up and came up with a solution similar to @1letter did above:

    related_slider_banners = RelationList(
        title=_(u'Slider Banners'),
        description=_(u'These banners will be used in the slider'),

			'recentlyUsed': True,
			'basePath': '/',
			'mode': 'auto',
            'favorites': get_favorites,
            'folderTypes': ['Folder', 'LIF', 'LRF'],
            'selectableTypes' : ['dry_banner'],

The pattern options allow you to define functions that return custom values.

Its worth mentioning that pat-relateditems (which is bound to RelatedItemsFieldWidget) isn't really designed for "dropdown only" select2 fields.

I recently added this in plone.app.z3cform>=4.4.0 ... see Select2FieldWidget here https://github.com/plone/plone.app.z3cform/blob/master/plone/app/z3cform/widgets/select.py#L48 but note, that these versions target Plone 6.1 currently (though its 100% Plone 6.0 compatible because I use it in production :wink: )

There's also effort going on in refactoring the pat-relateditems pattern to a "miller column browser" like file browser (kudos to @MrTango) so hopefully with this update we get rid of the currently patched and ancient select2==3.5.4 version and can update select2 to the latest version... or even better -> get rid of select2 in favor of another fancy pancy select field JS library :slight_smile: