Module plone.formwidget.autocomplete.widget, line 63, in __call__ AttributeError: 'SimpleVocabulary' object has no attribute 'search'

Ok, I think I've found that there are at least two other threads that seem to be attempting to achieve the same goal as I was, to use the autocomplete widget to use work with dynamic vocabularies. Similar to Andreas, I became rather distraught over the various failures using the any of the autocomplete widgets listed in the documentation.

Using the directives every time (AutocompleteFieldWidget, AutocompleteMultiFieldWidget) things would just blow up like the examples above. Very, very annoying, but hey free software, right?

Being OCD I ripped things apart to just try to understand what was happening or not. Basically (as Kim says) your source must implement the IQuerySource interface from z3c.formwidget.query somehow and that too will lead you on a wild goose chase. The documentation is very skimpy, incorrect, or non-existent about what and how to implement this widget properly.

Autocomplete widget based on jQuery Autocomplete. Requires a Choice field with a query source.

Reading the documentation on vocabularies again, led me to look at the list of common ones.

Since my content type is DX I was immediately excited that plone.principalsource which is oh so casually mentioned there says that it: provides several vocabularies that are useful for selecting users and groups in a Dexterity context...

However, the Plone Vocab Doc's method of adding this package to your addon I believe is either incorrect or out of date. After doing a few hours of google-fu I found an addon in the collective that seemed to have implemented widgets within a DX content type. I then sorta did a reverse search from there to get to the collective repo and find it there where I could examine things more carefully. After a look at the code, I did the following:

  • edited my setup.py and added plone.principalsource to install_requires=
  • added a line in my package's configure.zcml include package="plone.principalsource"
  • added directives.widget ( empid=AjaxSelectFieldWidget ) to my schema.Choice field
  • added from plone.app.z3cform.widget import AjaxSelectFieldWidget
  • re-ran buildout to install.

It worked!

After I made principlesource a named utility, was I finally able to get the field widget working as advertised.

However, the supposed autocomplete version did not work. I could only get the Ajax versions to load correctly.

Now, just because it works doesn't mean its right. What do you guys think? Is this correct or at least a starting point?

3 Likes