AJAX autocomplete widget for z3c.form
Project description
Autocomplete widget
gocept.autocomplete provides an autocomplete widget for z3c.form based on YUI AutoComplete.
>>> import zope.app.testing.functional >>> root = zope.app.testing.functional.getRootFolder() >>> import gocept.autocomplete.tests.color >>> house = gocept.autocomplete.tests.color.House() >>> root['house'] = house
>>> import zope.testbrowser.testing >>> b = zope.testbrowser.testing.Browser() >>> b.handleErrors = False
The 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
<?xml...
...<script src=".../autocomplete-min.js"...
...<input id="form-widgets-color"...
...<div id="form-widgets-color-container"...
...DS_XHR("http://localhost/house/@@index.html/++widget++color/@@autocomplete-search"...
...new YAHOO.widget.AutoComplete( "form-widgets-color", "form-widgets-color-container"...
The autocompletion is populated via a view registered on the widget:
>>> 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.contents
red
ruby
But we can still enter any value we want and have it saved:
>>> b.open('http://localhost/house')
>>> b.getControl('Color').value = 'foo'
>>> b.getControl(name='form.buttons.apply').click()
>>> print b.contents
<?xml...
...foo...
Changes
0.1 (unreleased)
first release
NOTE: still missing security declarations on the autocomplete-search view. This means anyone can query the source for values.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file gocept.autocomplete-0.1dev.tar.gz.
File metadata
- Download URL: gocept.autocomplete-0.1dev.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce538df05e4fa9d620dd52bb1d16a7d516f48913fe6e52226e0f577d9c516a06
|
|
| MD5 |
aaafcb1c3ded6dfd906c02d225adcf3e
|
|
| BLAKE2b-256 |
0abeb40c4b0f25ebc46c73bdbf8975fa0674331f249f969fadf23052f343c201
|