Combobox is a combination of a drop-down list or list box and a single-line textbox, allowing the user either to choose from the list of existing options.
Combobox tag is "combobox" i.e.
<comp:combobox name="number_of_employees"/>
A combobox is a subclass of __ItemListComponent, which is compound by a list of __ItemComponent instances. A __ItemComponent is a component containing a pair text, value. We can setup the combobox items by ussing the "item" tag: i.e. <comp:combobox name="number_of_employees">
<comp:item value="1" text="1 to 10"/>
<comp:item value="2" text="11 to 20"/>
<comp:item value="3" text="21 to 50"/>
<comp:item value="4" text="more than 50"/>
</comp:combobox>
We can also setup a combobox within the eventhandler code (typically within the beforeRender (each time the view is rendered) or within the component create event (once the component is created). i.e. public function beforeRender() {
$combobox = $this->getComponent('number_of_employees');
$combobox->addItem(new __Item(1, '1 to 10'));
$combobox->addItem(new __Item(2, '11 to 20'));
$combobox->addItem(new __Item(3, '21 to 50'));
$combobox->addItem(new __Item(4, 'more than 50'));
}
We can select only one item within a combobox, which represents the value for that component. For that purpose, we can: i.e. <comp:combobox name="number_of_employees">
<comp:item value="" text="Please select" selected="true"/>
<comp:item value="1" text="1 to 10"/>
<comp:item value="2" text="11 to 20"/>
<comp:item value="3" text="21 to 50"/>
<comp:item value="4" text="more than 50"/>
</comp:combobox>
A combobox, as a value holder, returns the value of the selected item as a result of call to the getValue. i.e. public function number_of_employees_change(__UIEvent &$event) {
//get the value of the selected item within the combo:
$combo_value = $event->getComponent()->getValue();
//...
}
}Default events associated to a combobox are the same as associated to a html select element. Most usefull is the change event, raised when the user change the selection. See the combobox component in action here: http://www.lionframework.org/components/combobox.html
__UIComponent
|
--__UIContainer
|
--__InputComponent
|
--__ItemListComponent
|
--__ComboBoxComponent
|