Coverage for gws-app/gws/plugin/model_widget/select/__init__.py: 0%
24 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1"""Select widget."""
3from typing import Optional, Any
5import gws
6import gws.base.model.widget
8gws.ext.new.modelWidget('select')
11# see also js/ui/select
12class ListItem(gws.Data):
13 value: Any
14 text: str
15 extraText: Optional[str]
16 level: Optional[int]
19class ListItemConfig(gws.Data):
20 value: Any
21 text: Optional[str]
22 extraText: Optional[str]
23 level: Optional[int]
26class Config(gws.base.model.widget.Config):
27 items: list[ListItemConfig]
28 withSearch: bool = False
31class Props(gws.base.model.widget.Props):
32 items: list[ListItem]
33 withSearch: bool
36class Object(gws.base.model.widget.Object):
37 def props(self, user):
38 items = [
39 ListItem(value=it.value, text=it.text or str(it.value))
40 for it in self.cfg('items', default=[])
41 ]
42 return gws.u.merge(
43 super().props(user),
44 items=items,
45 withSearch=bool(self.cfg('withSearch'))
46 )