Package: horae.autocomplete
IntroductionThehorae.autocompletepackage provides autocomplete fields and widgets forzope.formlibbased on theautocomplete widget of jQuery UI.UsageThere are two types of autocomplete fields available:AutocompleteListAllows selection of multiple valuesAutocompleteChoiceAllows selection of one valueTo enable autocompletion for a list or choice field simply replace theListrespectively theChoicefromzope.schemaby the one provided inhorae.autocomplete.fields:from zope import interface, schema

from horae.autocomplete import fields

class ISampleSchema(interface.Interface):
    """ A schema using an autocomplete choice and list field
    """

    choice = fields.AutocompleteChoice(
        values = (u'one', u'two', u'three',)
    )

    list = fields.AutocompleteList(
        value_type = schema.Choice(
            values=(u'Tag 1', u'Tag 2', u'Tag 3',)
        )
    )TheAutocompleteChoicefield takes exactly the same parameters as theChoicefield
provided byzope.schema. The same is true for
theAutocompleteListfield which takes the same parameters as theListfield ofzope.schemawith the only restriction that
thevalue_typehas to be either aChoiceorTextLinefield.Advanced usageValue providersThe available values presented to the user when entering a term into the field are provided
by adapters implementinghorae.autocomplete.interfaces.IValueProvider. There are default
value providers already implemented which look up the available values based on the given
input in the vocabulary of the field. This is done by iterating over the values in the
vocabulary and check whether a value matches the given input. For very large or infinite
vocabularies this is quite expensive or not possible at all. To efficiently support such
vocabularies value providers may be overridden by registering a more specific adapter
implementinghorae.autocomplete.interfaces.IValueProvider. Those adapters are looked
up in the following order where the first one found is used:Named contextual providerA value provider adapting thecontext,fieldandrequestregistered with the
same name as the fieldNamed uncontextual providerA value provider adapting thefieldandrequestregistered with the same name as
the fieldContextual providerA value provider adapting thecontext,fieldandrequestUncontextual providerA value provider adapting thefieldandrequestExamples of custom value providers is found in thehorae.searchpackage which provides non iterable vocabularies and corresponding value providers which
use full text search in a catalog to look up the available values based on the input.Field providersAs mentioned in the previous chapter the value providers are adapters adapting at least thefieldand therequest. To look up those providers the field needs to be looked up
first. In most cases this is not an issue at all since the fields are defined by the schema
of the form. But in some cases the field is placed in the form only when rendering it which
would then require to render the whole form only to find the required field. To efficiently
support this use-case the way how a field is looked up may be overridden by registering an
adapter implementinghorae.autocomplete.interfaces.IFieldProviderand adapting thecontextandrequest.Dependenciesfanstaticzope.fanstaticjs.jqueryjs.jqueryuiChangelog1.0a1 (2012-01-16)Initial release