Skip to content

Commit 36b18d8

Browse files
committed
value could be array in combobox
1 parent 1664ed9 commit 36b18d8

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

examples/combobox.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
ComboBox(
2424
label="Your favorite car makers",
2525
multi_select=True,
26-
value="BMW, Volkswagen",
26+
value=["BMW, Volkswagen"],
2727
width="50%",
28+
on_change=lambda e: print("selected cars:", e.control.value),
2829
options=[
2930
combobox.Option("Select all", item_type="select_all"),
3031
combobox.Option("div1", item_type="divider"),
@@ -34,4 +35,28 @@
3435
combobox.Option("Mercedes-Benz"),
3536
],
3637
),
38+
ComboBox(
39+
label="Allows free form",
40+
multi_select=False,
41+
width="50%",
42+
allow_free_form=True,
43+
options=[
44+
combobox.Option("One"),
45+
combobox.Option("Two"),
46+
combobox.Option("Five"),
47+
],
48+
),
49+
ComboBox(
50+
label="Allows free form with multi-select",
51+
multi_select=True,
52+
width="50%",
53+
allow_free_form=True,
54+
options=[
55+
combobox.Option("Red"),
56+
combobox.Option("Green"),
57+
combobox.Option("Blue"),
58+
],
59+
),
3760
)
61+
62+
input()

pglet/combobox.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Literal, Optional
1+
from typing import List, Literal, Optional
22

33
from beartype import beartype
44

@@ -87,10 +87,15 @@ def label(self, value):
8787
# value
8888
@property
8989
def value(self):
90-
return self._get_attr("value")
90+
v = self._get_attr("value")
91+
if v and self.multi_select:
92+
return [x.strip() for x in v.split(",")]
93+
return v
9194

9295
@value.setter
9396
def value(self, value):
97+
if isinstance(value, List):
98+
value = ",".join(value)
9499
self._set_attr("value", value)
95100

96101
# placeholder

0 commit comments

Comments
 (0)