Bandbox"
(25 intermediate revisions by 9 users not shown) | |||
Line 2: | Line 2: | ||
= Bandbox = | = Bandbox = | ||
− | *Demonstration: [http://www.zkoss.org/zkdemo/ | + | *Demonstration: [http://www.zkoss.org/zkdemo/combobox/customizable_combobox Bandbox] |
*Java API: <javadoc>org.zkoss.zul.Bandbox</javadoc> | *Java API: <javadoc>org.zkoss.zul.Bandbox</javadoc> | ||
*JavaScript API: <javadoc directory="jsdoc">zul.inp.Bandbox</javadoc> | *JavaScript API: <javadoc directory="jsdoc">zul.inp.Bandbox</javadoc> | ||
+ | *Style Guide: [[ZK_Style_Guide/XUL_Component_Specification/Bandbox| Bandbox]] | ||
= Employment/Purpose = | = Employment/Purpose = | ||
− | A bandbox is a special text box that embeds a customizable popup window (aka., a dropdown window). Like comboboxes, a bandbox consists of an input box and a popup window. The popup window is opened automatically, when | + | A bandbox is a special text box that embeds a customizable popup window (aka., a dropdown window). Like comboboxes, a bandbox consists of an input box and a popup window. The popup window is opened automatically, when a user presses Alt+DOWN or clicks the magnifier button. |
Unlike comboboxes, the popup window of a bandbox could be anything. It is designed to give developers the maximal flexibility. A typical use is to represent the popup window as a search dialog. | Unlike comboboxes, the popup window of a bandbox could be anything. It is designed to give developers the maximal flexibility. A typical use is to represent the popup window as a search dialog. | ||
+ | |||
= Example = | = Example = | ||
Line 15: | Line 17: | ||
<source lang="xml" > | <source lang="xml" > | ||
− | <bandbox | + | <bandbox> |
− | + | <bandpopup> | |
− | + | <listbox style="max-width:300px" | |
− | + | onSelect="bd.value=self.selectedItem.label;bd.close();"> | |
− | + | <listhead> | |
− | + | <listheader label="Name"/> | |
− | + | <listheader label="Description"/> | |
− | + | </listhead> | |
− | + | <listitem> | |
− | + | <listcell label="John"/> | |
− | + | <listcell label="CEO"/> | |
− | + | </listitem> | |
− | + | <listitem> | |
− | + | <listcell label="Joe"/> | |
− | + | <listcell label="Engineer"/> | |
− | + | </listitem> | |
− | + | <listitem> | |
− | + | <listcell label="Mary"/> | |
− | + | <listcell label="Supervisor"/> | |
− | + | </listitem> | |
− | + | </listbox> | |
− | + | </bandpopup> | |
− | + | </bandbox> | |
− | + | </source> | |
− | + | ||
− | + | =Keyboard Navigation bandbox= | |
− | </ | + | |
− | </bandpopup> | + | * <code>Alt+DOWN</code> to pop up the list. |
+ | * <code>Alt+UP</code> or <code>ESC</code> to close the list. | ||
+ | |||
+ | =Properties= | ||
+ | == The Close Method == | ||
+ | A popup window could contain any components, so it is the developer’s job to close the popup and copy any needed value from it. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listbox width="200px" | ||
+ | onSelect="bd.value=self.selectedItem.label; bd.close();"> | ||
+ | </source> | ||
+ | |||
+ | In the above example, we copy the selected item's label to the bandbox, and then close the popup. | ||
+ | |||
+ | == Autodrop== | ||
+ | [[Image:ZKComRef_Bandbox_Autodrop.PNG]] | ||
+ | |||
+ | By default, the popup window won't be opened until user clicks the button, or presses <code>Alt+DOWN</code> on the keyboard. However, you can set the <code>autodrop</code> property to true and as soon as the user types a character the popup will be opened. This is helpful for novice users, but it might be annoying for experienced users. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <zk> | ||
+ | <bandbox id="bd" autodrop="true"> | ||
+ | <bandpopup> | ||
+ | ... | ||
+ | </bandpopup> | ||
+ | </bandbox> | ||
+ | </zk> | ||
+ | </source> | ||
+ | |||
+ | == The onOpen Event == | ||
+ | If the user opens the popup window the <code>onOpen</code> event is sent to the application. By using the <code>fulfill</code> attribute with the <code>onOpen</code> value as shown below, you can defer the creation of the popup window. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <bandbox id="test"> | ||
+ | <bandpopup fulfill="test.onOpen"> | ||
+ | ... | ||
+ | </bandpopup> | ||
</bandbox> | </bandbox> | ||
</source> | </source> | ||
− | = | + | Alternatively, you can prepare the popup window in Java by listening to the <code>onOpen</code> event, as depicted below. |
+ | |||
+ | <source lang="xml" > | ||
+ | <zk> | ||
+ | <bandbox id="band" onOpen="prepare()"/> | ||
+ | |||
+ | <zscript> | ||
+ | void prepare() | ||
+ | { | ||
+ | if (band.getPopup() == null) { | ||
+ | //create child elements | ||
+ | } | ||
+ | } | ||
+ | </zscript> | ||
+ | </zk> | ||
+ | </source> | ||
+ | |||
+ | == The onChanging Event == | ||
+ | Since a bandbox is also a text box, you are also able to listen to an <code>onChanging</code> event. By listening to this event, you can manipulate the popup window in any fashion. | ||
+ | The code below illustrates capturing the user key and displaying information accordingly. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <zk> | ||
+ | <bandbox id="band" autodrop="true" onChanging="suggest()"/> | ||
+ | <zscript> | ||
+ | void suggest() | ||
+ | { | ||
+ | if (event.value.startsWith("A")) { | ||
+ | //do something | ||
+ | } else if (event.value.startsWith("B")) { | ||
+ | //do another | ||
+ | } | ||
+ | } | ||
+ | </zscript> | ||
+ | </zk> | ||
+ | </source> | ||
+ | |||
− | {| | + | Notice that, when the <code>onChanging</code> event is received, the content of the bandbox has not changed. Therefore, you cannot get the <code>value</code> property of the bandbox. Instead, you should call [https://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/event/InputEvent.html#getValue-- org.zkoss.zk.ui.event.InputEvent.getValue()]. |
+ | |||
+ | == Constraint == | ||
+ | You could specify what value to accept for input controls by the use of the <code>constraint </code>property. | ||
+ | It could be a combination of <code>no empty</code>, and/or a regular expression. | ||
+ | |||
+ | To specify two or more constraints, use comma to separate them as follows. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <bandbox constraint="no empty,/^A/"/> | ||
+ | |||
+ | </source> | ||
+ | |||
+ | To specify a regular expression, you may have to use the character <code>/</code> to enclose the regular expression as follows. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <bandbox constraint="/^A/"/> | ||
+ | </source> | ||
+ | |||
+ | Notes: | ||
+ | |||
+ | * The above statement is XML, so do ''not'' use <code>\\</code> to specify a backslash. However typing <code>\\</code> is necessary, if writing in Java. | ||
+ | |||
+ | <source lang="java" > | ||
+ | new Bandbox().setConstraint("/.+@.+\\.[a-z]+/"); | ||
+ | </source> | ||
+ | |||
+ | * You are allowed to mix regular expressions with other constraints by separating them with a comma. | ||
+ | |||
+ | If you prefer to display different message to the default one, you can append the error message to the constraint with a colon. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <bandbox constraint="/^A/: only allowed the item start with A"/> | ||
+ | </source> | ||
+ | |||
+ | Notes: | ||
+ | |||
+ | * The error message, if specified, must be the last element and start with colon. | ||
+ | * To support multiple languages, you could use the 「l」 function as depicted in the '''Internationalization''' chapter. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <bandbox constraint="/^A/: ${c:l('err.startwith.required')}"/> | ||
+ | </source> | ||
+ | |||
+ | ==IconSclass== | ||
+ | {{versionSince| 8.6.2}} | ||
+ | Specify the sclass name of the Bandbox button icon. For built-in icon, please see [[ZK_Component_Reference/Base_Components/LabelImageElement]]. | ||
+ | |||
+ | =Inherited Functions= | ||
+ | |||
+ | Please refer to [[ZK_Component_Reference/Input/Textbox | Textbox]] for inherited functions. | ||
+ | |||
+ | =Supported Events= | ||
+ | |||
+ | {| class='wikitable' | width="100%" | ||
! <center>Name</center> | ! <center>Name</center> | ||
! <center>Event Type</center> | ! <center>Event Type</center> | ||
Line 57: | Line 185: | ||
Denotes 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. | Denotes 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. | ||
|} | |} | ||
+ | *Inherited Supported Events: [[ZK_Component_Reference/Input/Textbox#Supported_Events | Textbox]] | ||
− | =Supported | + | =Supported Molds= |
Available molds of a component are defined in lang.xml embedded in zul.jar. | Available molds of a component are defined in lang.xml embedded in zul.jar. | ||
− | {| | + | {| class='wikitable' | width="100%" |
! <center>Name</center> | ! <center>Name</center> | ||
! <center>Snapshot</center> | ! <center>Snapshot</center> | ||
|- | |- | ||
| <center>default</center> | | <center>default</center> | ||
− | | | + | |[[Image:bandbox_mold_default.png ]] |
|- | |- | ||
| <center>rounded</center> | | <center>rounded</center> | ||
− | | | + | |[[Image:bandbox_mold_rounded.png ]] |
− | } | + | {{versionSince| 5.0.0}} |
+ | |} | ||
=Supported Children= | =Supported Children= | ||
Line 75: | Line 205: | ||
*[[ZK_Component_Reference/Input/Bandpopup | Bandpopup ]] | *[[ZK_Component_Reference/Input/Bandpopup | Bandpopup ]] | ||
− | =Use | + | =Use Cases= |
− | {| | + | {| class='wikitable' | width="100%" |
! Version !! Description !! Example Location | ! Version !! Description !! Example Location | ||
|- | |- | ||
Line 86: | Line 216: | ||
=Version History= | =Version History= | ||
− | + | {{LastUpdated}} | |
− | {| | + | {| class='wikitable' | width="100%" |
! Version !! Date !! Content | ! Version !! Date !! Content | ||
|- | |- |
Latest revision as of 01:28, 17 June 2024
Bandbox
Employment/Purpose
A bandbox is a special text box that embeds a customizable popup window (aka., a dropdown window). Like comboboxes, a bandbox consists of an input box and a popup window. The popup window is opened automatically, when a user presses Alt+DOWN or clicks the magnifier button.
Unlike comboboxes, the popup window of a bandbox could be anything. It is designed to give developers the maximal flexibility. A typical use is to represent the popup window as a search dialog.
Example
<bandbox>
<bandpopup>
<listbox style="max-width:300px"
onSelect="bd.value=self.selectedItem.label;bd.close();">
<listhead>
<listheader label="Name"/>
<listheader label="Description"/>
</listhead>
<listitem>
<listcell label="John"/>
<listcell label="CEO"/>
</listitem>
<listitem>
<listcell label="Joe"/>
<listcell label="Engineer"/>
</listitem>
<listitem>
<listcell label="Mary"/>
<listcell label="Supervisor"/>
</listitem>
</listbox>
</bandpopup>
</bandbox>
Alt+DOWN
to pop up the list.Alt+UP
orESC
to close the list.
Properties
The Close Method
A popup window could contain any components, so it is the developer’s job to close the popup and copy any needed value from it.
<listbox width="200px"
onSelect="bd.value=self.selectedItem.label; bd.close();">
In the above example, we copy the selected item's label to the bandbox, and then close the popup.
Autodrop
By default, the popup window won't be opened until user clicks the button, or presses Alt+DOWN
on the keyboard. However, you can set the autodrop
property to true and as soon as the user types a character the popup will be opened. This is helpful for novice users, but it might be annoying for experienced users.
<zk>
<bandbox id="bd" autodrop="true">
<bandpopup>
...
</bandpopup>
</bandbox>
</zk>
The onOpen Event
If the user opens the popup window the onOpen
event is sent to the application. By using the fulfill
attribute with the onOpen
value as shown below, you can defer the creation of the popup window.
<bandbox id="test">
<bandpopup fulfill="test.onOpen">
...
</bandpopup>
</bandbox>
Alternatively, you can prepare the popup window in Java by listening to the onOpen
event, as depicted below.
<zk>
<bandbox id="band" onOpen="prepare()"/>
<zscript>
void prepare()
{
if (band.getPopup() == null) {
//create child elements
}
}
</zscript>
</zk>
The onChanging Event
Since a bandbox is also a text box, you are also able to listen to an onChanging
event. By listening to this event, you can manipulate the popup window in any fashion.
The code below illustrates capturing the user key and displaying information accordingly.
<zk>
<bandbox id="band" autodrop="true" onChanging="suggest()"/>
<zscript>
void suggest()
{
if (event.value.startsWith("A")) {
//do something
} else if (event.value.startsWith("B")) {
//do another
}
}
</zscript>
</zk>
Notice that, when the onChanging
event is received, the content of the bandbox has not changed. Therefore, you cannot get the value
property of the bandbox. Instead, you should call org.zkoss.zk.ui.event.InputEvent.getValue().
Constraint
You could specify what value to accept for input controls by the use of the constraint
property.
It could be a combination of no empty
, and/or a regular expression.
To specify two or more constraints, use comma to separate them as follows.
<bandbox constraint="no empty,/^A/"/>
To specify a regular expression, you may have to use the character /
to enclose the regular expression as follows.
<bandbox constraint="/^A/"/>
Notes:
- The above statement is XML, so do not use
\\
to specify a backslash. However typing\\
is necessary, if writing in Java.
new Bandbox().setConstraint("/.+@.+\\.[a-z]+/");
- You are allowed to mix regular expressions with other constraints by separating them with a comma.
If you prefer to display different message to the default one, you can append the error message to the constraint with a colon.
<bandbox constraint="/^A/: only allowed the item start with A"/>
Notes:
- The error message, if specified, must be the last element and start with colon.
- To support multiple languages, you could use the 「l」 function as depicted in the Internationalization chapter.
<bandbox constraint="/^A/: ${c:l('err.startwith.required')}"/>
IconSclass
Since 8.6.2 Specify the sclass name of the Bandbox button icon. For built-in icon, please see ZK_Component_Reference/Base_Components/LabelImageElement.
Inherited Functions
Please refer to Textbox for inherited functions.
Supported Events
Event: OpenEvent
Denotes 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. |
- Inherited Supported Events: Textbox
Supported Molds
Available molds of a component are defined in lang.xml embedded in zul.jar.
Since 5.0.0 |
Supported Children
* Bandpopup
Use Cases
Version | Description | Example Location |
---|---|---|
Version History
Version | Date | Content |
---|---|---|