Hi,
i have a Custom Form with a Multiselect List. In Plone5 it is rendered as a SelectFieldWidget from plone.app.widgets. I would like to modify the pattern-options for pat-select2. If i do this via the Resource-Registry Pattern-Option-Tab then it's global. That is not what i want.
I would like change the Pattern Option only in this Custom Form. What should i do? Can i set the Option in updateWidgets-Method? Or should i register a PatternSettingsAdapter like this:
# https://www.nathanvangheem.com/news/customizing-javascript-pattern-options-in-plone-5
import json
from Products.CMFPlone.interfaces import IPatternsSettings
class PatternSettingsAdapter(object):
implements(IPatternsSettings)
def __init__(self, context, request, field):
self.request = request
self.context = context
self.field = field
def __call__(self):
return {'data-pat-select2': json.dumps({"placeholder": "Select a Category"})}
<adapter
for="* * *"
factory=".mymodule.PatternSettingsAdapter"
provides="Products.CMFPlone.interfaces.IPatternsSettings"
name="mymodule_settings" />
Here is another Question: what mean the zcml Attribute for="* * *"
. I only know "*"
or "concrete.Interfaces"
but what means the three asterisks?
Thats my Form:
# Schema Definition of Form
class ITestSelectWidgetForm(model.Schema):
directives.widget(jobcategories='plone.app.z3cform.widget.SelectFieldWidget')
jobcategories = schema.List(
title=_(u'Categories'),
description=_(u'Please select....'),
value_type=schema.Choice(
vocabulary="my.jobabo.jobcategories",
)
)
# The Form
class TestSelectWidgetForm(AutoExtensibleForm, form.Form):
schema = ITestSelectWidgetForm
ignoreContext = True
label = _(u"Criteria")
description = _(u"")
def __init__(self, context, request):
super(TestSelectWidgetForm, self).__init__(context, request)
self.context = context
self.request = request
def updateFields(self):
logger.info("in updateFields")
super(TestSelectWidgetForm, self).updateFields()
def updateWidgets(self):
logger.info("in updateWidgets")
super(TestSelectWidgetForm, self).updateWidgets()
def updateActions(self):
logger.info("in updateActions")
super(TestSelectWidgetForm, self).updateActions()
def update(self):
logger.info("in update")
super(TestSelectWidgetForm, self).update()
@button.buttonAndHandler(u'Ok')
def handleApply(self, action):
logger.info("in handleApply")
data, errors = self.extractData()
if errors:
# TODO Handle the Errors
return
self.status = "Thank you very much!"
@button.buttonAndHandler(u"Cancel")
def handleCancel(self, action):
logger.info("in handleCancel")
# The View
TestSelectWidgetFormView = wrap_form(TestSelectWidgetForm)