Custom z3c.form field widget not showing up

z3c.form is giving me hard time with adding a custom widget.

I have this custom "XMLXPath" field (derived from TextLine):

https://bitbucket.org/onkopedia/zopyx.existdb/src/bf3d262ebd37994e0404d9ab2aa940621869e37d/zopyx/existdb/dx/fields.py?at=dexterity#cl-71

and I am trying to get the boilerplate ready for custom widget for this field (basically copy&paste
from the recurrence widget of Plone):

https://bitbucket.org/onkopedia/zopyx.existdb/src/bf3d262ebd37994e0404d9ab2aa940621869e37d/zopyx/existdb/dx/configure.zcml?at=dexterity#cl-34

https://bitbucket.org/onkopedia/zopyx.existdb/src/bf3d262ebd37994e0404d9ab2aa940621869e37d/zopyx/existdb/dx/widget.py?at=dexterity

The XMLXpath still shows up as standard TextLine widget and everything seems to be ignored.
Is there something missing for attaching this widget as default widget to the field?

-aj

just a quick note: the adapter is registered against the very generic IField interface from zope.schema. shouldn't it be your IXMLXPath field interface?
https://bitbucket.org/onkopedia/zopyx.existdb/src/bf3d262ebd37994e0404d9ab2aa940621869e37d/zopyx/existdb/dx/widget.py?at=dexterity#cl-59

Good shot. In the first version I was using IXMLPath instead (as seen in your widget code). This gives me this error:

Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 858, in do_defineMacro
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 533, in do_optTag_tal
Module zope.tal.talinterpreter, line 518, in do_optTag
Module zope.tal.talinterpreter, line 513, in no_tag
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 531, in do_optTag_tal
Module zope.tal.talinterpreter, line 513, in no_tag
Module zope.tal.talinterpreter, line 343, in interpret
Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
Module zope.tales.tales, line 696, in evaluate

  • URL: /home/ajung/.buildout/eggs/plone.app.z3cform-0.7.7-py2.7.egg/plone/app/z3cform/templates/macros.pt
  • Line 97, Column 46
  • Expression: <PathExpr standard:u'widget/@@ploneform-render-widget'>
  • Names:
    {'args': (),
    'context': <PloneSite at /d1>,
    'default': <object object at 0x7ff57e2c3b80>,
    'loop': {},
    'nothing': None,
    'options': {},
    'repeat': {},
    'request': <HTTPRequest, URL=http://dev1.veit-schiele.de:9080/d1/++add++xml_document>,
    'template': <zope.browserpage.viewpagetemplatefile.ViewPageTemplateFile object at 0x8e23c10>,
    'view': <plone.dexterity.browser.add.DefaultAddForm object at 0xb078dd0>,
    'views': <zope.browserpage.viewpagetemplatefile.ViewMapper object at 0xb1b7ed0>}
    Module zope.tales.expressions, line 217, in call
    Module Products.PageTemplates.Expressions, line 147, in _eval
    Module zope.tales.expressions, line 124, in _eval
    Module Products.PageTemplates.Expressions, line 97, in trustedBoboAwareZopeTraverse
    Module zope.traversing.adapters, line 126, in traversePathElement
  • traceback_info: (<XPathWidget 'form.widgets.metadata'>, '@@ploneform-render-widget')
    Module zope.traversing.namespace, line 112, in namespaceLookup
    Module Products.CMFPlone.patches.security, line 12, in traverse
    Module zope.traversing.namespace, line 329, in traverse
    LocationError: (<XPathWidget 'form.widgets.metadata'>, 'ploneform-render-widget')

So I switched to IField (as seen in other widget code).

So IXMLPath seems to be right but no idea where the LocationError is coming from and related to what.
I did not had time so far to dig through to z3c.form for finding what's going on here.

Andreas

searching for the definition of ploneform-render-widget, it's a browser view registered in plone.app.z3cform for z3c.form.interfaces.IWidget contexts.
your IXPathWidget interface has to subclass the z3c.form.interfaces.IWidget ( .existdb/src/bf3d262ebd37994e0404d9ab2aa940621869e37d/zopyx/existdb/dx/widget.py?at=dexterity#cl-29 ). i guess, that does the trick (it's also the case for the recurrence widget).

note, that z3c.form.interfaces.IFieldWidget, which your XPathFieldWidget implements, does not derive from z3c.form.interfaces.IWidget.

don't ask what the difference between IWidget and IFieldWidget is, and why the latter does not derive from the other. I don't know. i can even barely belive, that i'm answering z3c.form questions :wink:

1 Like

Gotcha - subclassing z3c.form.interfaces.IWidget did the job.
Thanks!
Andreas