Question

I'm trying to open a custom editform which would only show one field from a form with 12 fields:

class EditForm(dexterity.EditForm):
    grok.name('editCustom')
    grok.context(IInfo)

    def updateWidgets(self):
        super(EditForm, self).updateWidgets()
        self.widgets['alps'].mode = 'hidden'
        self.widgets['operationStatus'].mode = 'hidden'

# etc.

things work fine until I get to a field which is a MultiField list-choice:

        self.widgets['siteContact'].mode = 'hidden'

(this is the entry in the form.Schema):

siteContact = schema.List(
    title=_(u"Site Contact"),
    description =_(u"Select Site Contacts"),
    value_type=schema.Choice(vocabulary=("test.siteContact")),
    required=False,
)

but when I try to access the custom EditForm I get:

  Module z3c.form.widget, line 140, in render
  Module zope.component._api, line 109, in getMultiAdapter
ComponentLookupError: ((<Container at /test/first>, <HTTPRequest, URL=http://localhost:8080/test/first/@@editCustom>, <Products.Five.metaclass.EditForm object at 0x08F9D9F0>, <zope.schema._field.List object at 0x084844B0>, <OrderedSelectWidget 'form.widgets.siteContact'>), <InterfaceClass zope.pagetemplate.interfaces.IPageTemplate>, 'hidden')
Was it helpful?

Solution

I ran into the exact same problem and don't know if there's a fix or work around by now but if ordering doesn't matter, you could try schema.Set (or schema.FrozenSet) instead of schema.List. These all let you select multiple options. I've tested the Set options and they both work with the mode as hidden.

(1) Set/FrozenSet

field = zope.schema.Set(
   value_type=zope.schema.Choice(values=(1, 2, 3, 4)),
   default=set([1, 3]) )
widget = setupWidget(field)
widget.update()

widget.__class__
<class 'z3c.form.browser.select.SelectWidget'>

select widget: allows you to select one or more values from a set of given options

(2) List

field = zope.schema.List(
value_type=zope.schema.Choice(values=(1, 2, 3, 4)),
    default=[1, 3] )
widget = setupWidget(field)
widget.update()

widget.__class__
<class 'z3c.form.browser.orderedselect.OrderedSelectWidget'>

ordered-select: allows you to select one or more values from a set of given options and sort those options.

OTHER TIPS

It looks like you might be specifying the vocabulary incorrectly. Please change

schema.Choice(vocabulary=("test.siteContact"))

to

schema.Choice(vocabulary="test.siteContact")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top