Searchbox

From Documentation
Revision as of 08:09, 25 September 2019 by Rudyhuang (talk | contribs) (EE)

WarningTriangle-32x32.png This page is under construction, so we cannot guarantee the accuracy of the content!

Searchbox

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png
[ since 9.0.0 ]

Employment/Purpose

A dropdown list that allows users to search and select items.

Example

<zscript>
ListModel model = new ListModelArray(new String[] {
  "North America", "South America", "Europe", "Asia", "Africa", "Oceania", "Antarctica"
});
</zscript>
<searchbox model="${model}" placeholder="An unknown place" autoclose="true">
   <template name="model">
       <html><![CDATA[
       <i class="z-icon-globe"></i> ${each}
       ]]></html>
   </template>
</searchbox>

Mouseless Entry Searchbox

  • UP or DOWN to pop up the list if focused.
  • ESC to close the list.
  • UP, DOWN, HOME, END, PAGE UP and PAGE DOWN to change the selection of the items from the list.
  • ENTER to confirm the change of selection.

Properties

Autoclose

Sets whether to automatically close the list if a user is selected any item. The default value is false. It means even the user selected an item, the list still remains open. You might want to set it as true in single selection mode (multiple=false).

Disabled

Sets whether it is disabled. A list can be still opened programmatically by calling open() even the component is in disabled state.

ItemConverter

By implementing your own Converter, you can generate the label that represents the selected items. The default implementation is joining all the toString() result of items by commas.

ItemRenderer

By implementing your own ItemRenderer, you can generate the HTML fragment for the data model. Normally you would like to use the default implementation and use <template name="model"> instead.

Model

Since this component doesn't accept any child, you must specify a ListModel.

If a ListSubModel is provided, all the items will not be rendered to the client directly. Instead, users must type a keyword to search for a subset of the list. It's suitable for a large model.

Notice: If you assign a ListModel to a searchbox, you should enable the multiple selection with the ListModel. Please do not set multiple on searchbox directly, set multiple on the model instead.

...
List Items = new ArrayList();
for (int i = 0; i < 1000; i++) {
	Items.add("data "+i);
}
ListModelList model = new ListModelList(Items);
model.setMultiple(true);
...

<searchbox model="${model}" ... />

Multiple

Sets whether multiple selections are allowed.

Open

Drops down or closes the list of items.

Placeholder

Sets the placeholder text that is displayed when the selected item is empty.

SearchMessage

Sets the placeholder message of the search text field. The default is "Type to search".

SelectedItem

Returns the selected item, or null if no item is selected. When multiple is true, it returns the first of the selected items.

Don't use MVVM annotations in both selectedItem and selectedItems at the same time since @save selectedItem will deselect all of the currently selected items first.

SelectedItems

Returns all selected items.

Supported Events

Name
Event Type
onAfterRender
Event: Event

Notifies one that the model's data has been rendered.

onSelect
Event: SelectEvent

Represents an event caused by the user that the list selection is changed at the client.

onOpen
Event: OpenEvent

Denotes that the user has opened or closed a component. Note: unlike onClose, this event is only a notification. The client sends this event after opening or closing the component.

onSearching
Event: Event

Notifies one that the user is searching by keywords.

Supported Children

* none

Version History

Last Update : 2019/09/25


Version Date Content
9.0.0 September 2019 ZK-4380: Provide a Searchbox component



Last Update : 2019/09/25

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.