gocept.autocomplete

AJAX autocomplete widget for z3c.form
Download

gocept.autocomplete Ranking & Summary

Advertisement

  • Rating:
  • License:
  • ZPL
  • Publisher Name:
  • gocept

gocept.autocomplete Tags


gocept.autocomplete Description

AJAX autocomplete widget for z3c.form gocept.autocomplete is a library that provides an autocomplete widget for z3c.form. The widget is useful if you want to provide the user with a list of suggestions for a field, but still want to accept anything else that is entered, too. The UI-part of the widget is YUI AutoComplete < http://developer.yahoo.com/yui/autocomplete/ >.zc.resourcelibrary is used to integrate the YUI library in HTML, so this package is incompatible with packages using hurry.resource.To use the widget, and provide a source that implements gocept.autocomplete.interfaces.ISearchableSource. This means two things, one, your source must provide a search() method so it can be queried for values (with whatever has been entered so far as the query) and two, you must always return True from the __contains__() method, so that the user is free to enter a value that is not part of the suggestions.No further configuration is required, the widget is automatically registered for all zope.schema.IChoice fields with an ISearchableSource.As an example, we exercise the code from gocept.autocomplete.tests.color with the testbrowser:>>> import zope.app.testing.functional>>> root = zope.app.testing.functional.getRootFolder()>>> import gocept.autocomplete.tests.color>>> house = gocept.autocomplete.tests.color.House()>>> root = house>>> import zope.testbrowser.testing>>> b = zope.testbrowser.testing.Browser()>>> b.handleErrors = FalseThe AutocompleteWidget is an enhanced TextWidget. Thus, in display mode, it behaves just like a TextWidget:>>> b.open('http://localhost/house')>>> print b.contents< ?xml......< span id="form-widgets-color" class="text-widget autocomplete required choice-field" >< /span >...But in edit mode, it generates additional javascript code:>>> b.addHeader('Authorization', 'Basic mgr:mgrpw')>>> b.open('http://localhost/house')>>> print b.contents>> b.open('http://localhost/house/@@index.html/++widget++color/@@autocomplete-search')>>> print b.contents>>> b.open('http://localhost/house/@@index.html/++widget++color/@@autocomplete-search?q=r')>>> print b.contentsredrubyBut we can still enter any value we want and have it saved (there are two parts to make this work, one is that the source must always return True in its __contains__() method, and the other is that the widget uses a special TitledTokenizedTerm that uses the actual value for everything):>>> b.open('http://localhost/house')>>> b.getControl('Color').value = 'foo'>>> b.getControl(name='form.buttons.apply').click()>>> print b.contents< ?xml......foo...Grouped FormsA special case are group forms, who provide the field definitions in their groups. For this particular occasion, we've setup an ApartmentGroup and a form:>>> apartment = gocept.autocomplete.tests.color.Apartment()>>> root = apartmentThe widget traversal for grouped forms returns the correct search results:>>> b.open('http://localhost/apartment/@@grouped.html/++widget++color/@@autocomplete-search?q=r')>>> print b.contentsredruby>>> b.open('http://localhost/apartment/@@grouped.html/++widget++number/@@autocomplete-search?q=1')>>> print b.contents12A12 Requirements: · Python What's New in This Release: · configure.zcml no longer includes zope.app.zcmlfiles, it was moved to ftesting.zcml. · Described the dependency on zc.resourcelibrary in README which makes this package incompatible with packages using hurry.resource.


gocept.autocomplete Related Software