espenmn
(Espen)
1
I have a related items field defined with:
relatedProjects = RelationList(
title=_(u'label_related_items', default=u'Prosjekter'),
default=[],
value_type=RelationChoice(
title=u'Prosjekter',
source=CatalogSource(portal_type=['project']),
),
required=False,
)
Which works find, but the widget 'search' starts from current folder (see screenshot).
In other words, the user needs to click on 'home' and search from there.
Is there a way to have the path default to home or some other folder?
alert
(Alessandro Pisa)
2
Try with something like this:
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform import directives
directives.widget(
"relatedProjects",
RelatedItemsFieldWidget,
pattern_options={"mode": "auto", "favorites": []},
)
More possible patter options here: https://github.com/plone/mockup/blob/master/mockup/patterns/relateditems/pattern.js#L3
espenmn
(Espen)
3
Thanks a lot, this seems to work
directives.widget(
'relatedItems',
RelatedItemsFieldWidget,
pattern_options={
'basePath': '/',
"mode": "auto",
"favorites": []
}
)
In the docs, basePath should default to '/', so I am not sure what happens here.
One strange thing: When I set base path to
'basePath': '/prosjekter',
The widget starts at '/r' (which does not exist).
1letter
(Jan)
4
That's what i do:
from zope import schema
from zope.interface import provider
from plone import api
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform import directives
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import model
def basePath(context=None):
uid = api.portal.get_registry_record('uid_of_configurable_folder', default = None)
if not uid:
# Root Portal Path
folder = api.portal.get()
else:
# Folder Start Path
folder = api.content.get(UID=uid)
return '/'.join(folder.getPhysicalPath())
@provider(IFormFieldProvider)
class IContact(model.Schema):
model.fieldset(
'contact',
label = _(u'Contact'),
fields = ['supervisor']
)
supervisor = schema.Choice(
title=_(u"Supervisor"),
description=_(u"Select the Supervisior"),
required=True,
vocabulary='plone.app.vocabularies.Catalog',
)
directives.widget(
'supervisor',
RelatedItemsFieldWidget,
pattern_options={
'selectableTypes': ['Supervisor'],
'basePath': basePath
}
)
2 Likes
espenmn
(Espen)
5
Is this a record you have added (never heard about it)
Am I understanding your right if:
basePath should no be /supervisors, but (for example) Plone/supervisors ?
1letter
(Jan)
6
the full path from ZMI root, yes.
The record is a custom record, not a Plone Registry Entry. It's only an example for configurable Paths
mtrebron
(Norbert )
7
Nice one! In the same way, you can return dynamic favorites dependent on context
espenmn
(Espen)
8
Is it possible to set base path in xml <schema> <field> ?
1 Like
pigeonflight
(David Bain (Will Theme Plone Sites))
10
Did anyone figure out how to do this with Dexterity XML?
@espenmn
espenmn
(Espen)
11
At the moment: I consider it 'not possible', I could not find any way.
pigeonflight
(David Bain (Will Theme Plone Sites))
12
So I will have to use a schema source....