A searchable dynamic vocabulary for a 1:1 field in Dexterity content-type?

Situation: we need to implement a staff member content-type in Dexerity where one field of the content-types represents the user in LDAP (through its DN). For the user prospective:

  • user enters a query into the search field
  • an ajax search performs a search in LDAP and returns a list of candidate where each
    candidate is tuple (DN, fullname of person).

So is there a reasonable widget for z3c.form/Dexterity that supports an AJAX search and the storage of DN + fullname?

The AjaxSelectFieldWidget is not working well here:

  • it defines a 1:N relation (not 1:1, could be check with @invariant but ugly)
  • the specified vocabulary must be dynamic and it must be searchable (I made a SimpleVocabulary
    search()able with a subclass)
  • a dynamic vocabulary does not work properly in case of validation errors or when the content-type
    is in the add-phase and not persisted yet. In this case you need to pick up the related values from the
    request and construct a vocabulary on-the-fly in order to render the widget properly.
  • the code above leads to "Wrong contained type" validation error.


    directives.widget('idm_link2', AjaxSelectFieldWidget, vocabulary='unimr.staff.persons.idmlink')
    idm_link2 = schema.List(
        title=_(u'Person IDM Link'),

a common mistake is having unicode values in the vocabulary and trying to set a str, or vice-versa.