Related items

November 2, 2023 ยท View on GitHub

Show a widget to select related items.

Configuration

OptionTypeDefaultDescription
attributesarray['UID', 'Title', 'portal_type', 'path']This list is passed to the server during an AJAX request to specify the attributes which should be included on each item.
basePathstringset to rootPath.Start browse/search in this path.
breadcrumbTemplatestringTemplate to use for a single item in the breadcrumbs.
breadcrumbTemplateSelectorstringnullSelect an element from the DOM from which to grab the breadcrumbTemplate.
closeOnSelectbooleantrueSelect2 option. Whether or not the drop down should be closed when an item is selected.
contextPathstringPath of the object, which is currently edited. If this path is given, this object will not be selectable.
dropdownCssClassstring'pattern-relateditems-dropdown'Select2 option. CSS class to add to the drop down element.
favoritesarray[]Array of objects. These are favorites, which can be used to quickly jump to different locations. Objects have the attributes "title" and "path".
maximumSelectionSizeinteger-1The maximum number of items that can be selected in a multi-select control. If this number is less than 1 selection is not limited.
minimumInputLengthinteger0Number of characters necessary to start a search.
modestringInitial widget mode. Possible values: are 'auto', 'search' and 'browse'. If set to 'search', the catalog is searched for a searchterm. If set to 'browse', browsing starts at basePath. Default: 'browse', which means the search and browse in separated tabs. Auto would combine global search and browse in one selection.
orderablebooleantrueWhether or not items should be drag-and-drop sortable.
pageSizeinteger10Batch size to break down big result sets into multiple pages.
recentlyUsedbooleanfalseShow the recently used items dropdown.
recentlyUsedMaxItemsinteger20Maximum items to keep in recently used list. 0: no restriction.
resultTemplatestringRefer to sourceTemplate for an item in the in the list of results. Refer to source for default.
resultTemplateSelectorstringnullSelect an element from the DOM from which to grab the resultTemplate.
rootPathstring"/"Only display breadcrumb path elements deeper than this path.
rootUrlstringVisible URL up to the rootPath. This is prepended to the currentPath to generate submission URLs.
scanSelectionbooleanScan the list of selected elements for other patterns.
selectableTypesarraynullIf the value is null all types are selectable. Otherwise, provide a list of strings to match item types that are selectable.
selectionTemplatestringRefer to sourceTemplate for element that will be used to construct a selected item.
selectionTemplateSelectorstringnullSelect an element from the DOM from which to grab the selectionTemplate.
separatorstring','Select2 option. String which separates multiple items.
sortOnstringnullIndex on which to sort on. If null, will default to term relevance (no sort) when searching and folder order (getObjPositionInParent) when browsing.
sortOrderstring'ascending'Sort ordering.
tokenSeparatorsarray[",", " "]Select2 option, refer to select2 documentation.
toolbarTemplatestringTemplate for element to which toolbar items will be appended.
toolbarTemplateSelectorstringnullSelect an element from the DOM from which to grab the toolbarTemplate.
uploadbooleanAllow file and image uploads from within the related items widget.
uploadAllowViewstringView, which returns a JSON response in the form of {allowUpload: true}, if upload is allowed in the current context.
vocabularyUrlstringnullThis is a URL to a JSON-formatted file used to populate the list
widthstring'100%'Specify a width for the widget.

Default, mode "browse" (separate browse and search tabs)

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems='{"selectableTypes": ["Document"], "vocabularyUrl": "relateditems-test.json"}'
/>

Default, mode "auto" (search/browser combined)

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems="width:30em;
                            mode:auto;
                            vocabularyUrl:relateditems-test.json"
/>

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems="width:30em;
                            mode:search;
                            vocabularyUrl:relateditems-test.json"
/>

Default, mode browse, favorites, recently used and upload

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems='{"vocabularyUrl": "relateditems-test.json", "favorites": [{"title": "Projects", "path": "/path"}], "recentlyUsed": true, "upload": true}'
/>

Existing values, some bad

<input
    type="text"
    class="pat-relateditems"
    value="asdf1234gsad,sdfbsfdh345,asdlfkjasdlfkjasdf,kokpoius98"
    data-pat-relateditems="width:30em; vocabularyUrl:relateditems-test.json"
/>

Selectable Types

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems='{"selectableTypes": ["Document"], "vocabularyUrl": "relateditems-test-selectable.json"}'
/>

Select a single item

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems='{"selectableTypes": ["Document"], "vocabularyUrl": "relateditems-test.json", "maximumSelectionSize": 1}'
/>

Mode "browse", Upload

<input
    type="text"
    class="pat-relateditems"
    data-pat-relateditems='{"selectableTypes": ["Image", "File"], "vocabularyUrl": "relateditems-test.json", "upload": true}'
/>