Skip to main content

ComboBox

A ComboBox combines a text field and a dropdown giving people a way to select an option from a list or enter their own choice.

Examples​

import pglet
from pglet import ComboBox, combobox

page = pglet.page("combobox-test")
page.horizontal_align = "stretch"
page.add(
ComboBox(
label="Your favorite car makers",
multi_select=True,
value=["BMW, Volkswagen"],
width="50%",
on_change=lambda e: print("selected cars:", e.control.value),
options=[
combobox.Option("Select all", item_type="select_all"),
combobox.Option("div1", item_type="divider"),
combobox.Option("BMW"),
combobox.Option("Toyota"),
combobox.Option("Volkswagen"),
combobox.Option("Mercedes-Benz"),
],
),
ComboBox(
label="Allows free form",
multi_select=False,
width="50%",
allow_free_form=True,
on_focus=lambda e: print("on_focus!"),
on_blur=lambda e: print("on_blur!"),
options=[
combobox.Option("One"),
combobox.Option("Two"),
combobox.Option("Five"),
],
),
ComboBox(
label="Allows free form with multi-select and error message",
multi_select=True,
width="50%",
allow_free_form=True,
error_message="This field cannot be left blank!",
options=[
combobox.Option("Red"),
combobox.Option("Green"),
combobox.Option("Blue"),
],
),
)

input()

Properties​

NameTypeDefaultDescription
valuestringkey value of the selected option, comma-separated list of selected options' keys if multiSelect is set to true or a text entered by a user if allowFreeForm is set to true.
labelstringLabel to display above the control.
placeholderstringThe short hint displayed in the control before the user selects or types a value.
errorMessagestringStatic error message displayed below the ComboBox.
multiSelectboolfalseWhether multi-choice selections are allowed or not.
allowFreeFormboolfalseWhether the ComboBox allows freeform user input, rather than restricting to the provided options.
autoCompletebooltrueWhether the ComboBox auto completes. As the user is entering text, potential matches will be suggested from the list of options. If the ComboBox is expanded, this will also scroll to the suggested option and give it a selected style.
focusedboolfalseWhen set to true the focus is set on the control when it's shown on the page or page opened.
datastringAdditional data attached to the control. The value is passed in change event data along with ComboBox selected value.

Events​

NameDescription
changeFires when the value of ComboBox is changed.
focusFires when the control has received focus.
blurFires when the control has lost focus.

Child controls​

Option control​

Option represents an item within ComboBox list.

NameTypeDefaultDescription
keystringOption's key. text value will be used instead if key is not specified.
textstringOption's display text. key value will be used instead if text is not specified.
itemTypestringnormalOption type: normal (default), divider, header, select_all.
disabledboolfalseDefines whether an item in a ComboBox is selectable or not.