Autocomplete from external source for dexterity field

Hi !

How can i configure an ajax autocompletion from an external source for a dexterity field ( in Plone 5)
(let's say the external source is: json output from php-mysql)

Any help / link would be apreciated

PS: This is not something I have done

I am not really sure what you need help to (do), but I think this is what you should do.

  1. First you need to define a vocabulary. I would start by making a 'normal' vocabulary, like described here https://github.com/plone/plone.formwidget.autocomplete/tree/master/plone/formwidget/autocomplete

and when you got that working, modify the vocabulary

  1. then you need to read the Json data (and construct the vocabulary). Does the data change all the time ( = you have to change the vocabulary 'again'). Maybe you have to decide what to do if the external source goes down ?

Reading the Json data is quite easy, maybe you can use something from here:

A vocabulary is static (it gets all its values on creation). Should that not be flexible enough, there is a generalization (called "Source") which allows for dynamic value determination,. Not sure, whether form.formwidget.autocomplete requires a vocabulary.

Thank you Espen !
The data does come from a changing database
The idea is to help data entry assistants with an autocomplete list where they can choose a valid option from the database. Let's say the name of a company , or individual of interest.

Thank you Dieter !
i'm going to check that option

I never understood how to make it 'not static', but some of the vocabularies seem to work correct 'anyway', for example I have one that uses the image scale sizes, and I think it works correct after adding more image scales:

The naming (and maybe the realization as well) in zope.schema related to the vocabulary option of the Choice field is not optimal. It allows as values either a vocabulary, a Source[Binder] or the ZA-registered name for a corresponding factory.

The LeadImpageSizeVocabulary in your example is not itself a "vocabulary" but a "vocabulary factory" (i.e. calling it results in a "vocabulary"). It constructs the real vocabulary (a SimpleVocabulary) at its end. The factory can return vocabularies with varying terms, either based on different contexts or because a database has changed.

You use a "Source[Binder]" instead of a simple vocabulary when the number of potential values is so large that it becomes unfeasible to handle them as a "unit". Examples are "selecting a user" (with a huge user base) , "selecting an object", etc.

2 Likes

thanks for explaining, things are a bit clearer now :slight_smile: