jZeno

pure java web development

  • Increase font size
  • Default font size
  • Decrease font size

How to use auto completion on text fields

E-mail Print PDF

As of jZeno 1.1.6 the StringEditor and DynaTextField support autocompletion, that is controlled by the server, but stored on the client (in the form of a cookie per auto completion field).

To activate this behaviour you must first set the field's setAutoComplete() property to true (auto completion is not enabled by default). After this you should make the text field use a stable client side identifier, as this identifier is used in the name of the cookie that will store the auto completion options. Use setClientId("MyAppAndFieldName") to give your text field a fixed id.

You can then add items to the history of the textfield by using the addAutoCompleteOption("Option") to add a new item to the list of options. Use setMaximumAutoCompleteItem() to set the maximum number of items in the list (default: 25). If you add an item twice to the list of options, the item is bumped to the top of the list. New items are always added to the top of the list.

If you wish to use a KeyActionCommand on a text field that also has auto completion enabled, and that KeyActionCommand responds to one of the keys that are used by the auto completion itself (typically RETURN), you should give the KeyActionCommand a delay, to give the auto completion a short timespan to fill in the selected option from the list. A good delay would be 250 ms.

TIP: Matching works by filtering on items that contain the entered text. So it does not only show items starting with the entered text.