dhxpyt.combobox

1from .combobox import Combobox
2from .combobox_config import ComboboxConfig
3
4__all__ = ["Combobox", "ComboboxConfig"]
class Combobox:
 13class Combobox:
 14    def __init__(self, config: ComboboxConfig = None, widget_parent: Any = None):
 15        """Initializes the Combobox instance."""
 16        if config is None:
 17            config = ComboboxConfig()
 18        config_dict = config.to_dict()
 19        self.combobox = js.dhx.Combobox.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))
 20    
 21    """ Combobox API Functions """
 22    
 23    def add_option(self, value: Union[Dict[str, Any], str], join: bool = True) -> None:
 24        """Adds a new item into the list of Combobox options."""
 25        self.combobox.addOption(value, join)
 26    
 27    def blur(self) -> None:
 28        """Removes focus from Combobox."""
 29        self.combobox.blur()
 30    
 31    def clear(self) -> None:
 32        """Clears the value set in the Combobox."""
 33        self.combobox.clear()
 34    
 35    def destructor(self) -> None:
 36        """Removes a Combobox instance and releases occupied resources."""
 37        self.combobox.destructor()
 38    
 39    def disable(self) -> None:
 40        """Disables Combobox on a page."""
 41        self.combobox.disable()
 42    
 43    def enable(self) -> None:
 44        """Enables a disabled Combobox."""
 45        self.combobox.enable()
 46    
 47    def focus(self) -> None:
 48        """Sets focus in the input without opening a popup with options."""
 49        self.combobox.focus()
 50    
 51    def get_value(self, as_array: bool = False) -> Union[str, int, List[Union[str, int]]]:
 52        """Gets id(s) of items from data collection selected in Combobox."""
 53        return self.combobox.getValue(as_array)
 54    
 55    def is_disabled(self) -> bool:
 56        """Checks whether a Combobox is disabled."""
 57        return self.combobox.isDisabled()
 58    
 59    def paint(self) -> None:
 60        """Repaints the Combobox."""
 61        self.combobox.paint()
 62    
 63    def set_value(self, ids: Union[str, int, List[Union[str, int]]]) -> None:
 64        """Selects option(s) in Combobox."""
 65        self.combobox.setValue(ids)
 66    
 67    """ Combobox Events """
 68    
 69    def add_event_handler(self, event_name: str, handler: Callable) -> None:
 70        """Helper to add event handlers dynamically."""
 71        event_proxy = create_proxy(handler)
 72        self.combobox.events.on(event_name, event_proxy)
 73    
 74    def on_after_close(self, handler: Callable[[], None]) -> None:
 75        """Fires after closing a list with options."""
 76        self.add_event_handler('afterClose', handler)
 77    
 78    def on_after_open(self, handler: Callable[[], None]) -> None:
 79        """Fires after opening a list with options."""
 80        self.add_event_handler('afterOpen', handler)
 81    
 82    def on_before_change(self, handler: Callable[[Union[str, int, List[Union[str, int]]]], Union[bool, None]]) -> None:
 83        """Fires before selection of a new option."""
 84        def event_handler(ids):
 85            result = handler(ids)
 86            if result is False:
 87                return js.Boolean(False)
 88        event_proxy = create_proxy(event_handler)
 89        self.combobox.events.on('beforeChange', event_proxy)
 90    
 91    def on_before_close(self, handler: Callable[[], Union[bool, None]]) -> None:
 92        """Fires before closing a list with options."""
 93        def event_handler():
 94            result = handler()
 95            if result is False:
 96                return js.Boolean(False)
 97        event_proxy = create_proxy(event_handler)
 98        self.combobox.events.on('beforeClose', event_proxy)
 99    
100    def on_before_open(self, handler: Callable[[], Union[bool, None]]) -> None:
101        """Fires before opening a list with options."""
102        def event_handler():
103            result = handler()
104            if result is False:
105                return js.Boolean(False)
106        event_proxy = create_proxy(event_handler)
107        self.combobox.events.on('beforeOpen', event_proxy)
108    
109    def on_blur(self, handler: Callable[[], None]) -> None:
110        """Fires when Combobox has lost focus."""
111        self.add_event_handler('blur', handler)
112    
113    def on_change(self, handler: Callable[[Union[str, int, List[Union[str, int]]]], None]) -> None:
114        """Fires when a new option is selected."""
115        self.add_event_handler('change', handler)
116    
117    def on_focus(self, handler: Callable[[], None]) -> None:
118        """Fires when Combobox has received focus."""
119        self.add_event_handler('focus', handler)
120    
121    def on_input(self, handler: Callable[[str], None]) -> None:
122        """Fires on typing text in an input of Combobox."""
123        self.add_event_handler('input', handler)
124    
125    def on_keydown(self, handler: Callable[[Any, Union[str, int, None]], None]) -> None:
126        """Fires when any key is pressed and an option of Combobox is in focus."""
127        self.add_event_handler('keydown', handler)
128    
129    """ Combobox Properties """
130    
131    @property
132    def css(self) -> str:
133        """Gets or sets the CSS classes for Combobox."""
134        return self.combobox.config.css
135    
136    @css.setter
137    def css(self, value: str) -> None:
138        self.combobox.config.css = value
139    
140    @property
141    def data(self) -> List[Dict[str, Any]]:
142        """Gets or sets the data objects for Combobox."""
143        return self.combobox.config.data
144    
145    @data.setter
146    def data(self, value: List[Dict[str, Any]]) -> None:
147        self.combobox.data.parse(js.JSON.parse(json.dumps(value)))
148    
149    @property
150    def disabled(self) -> bool:
151        """Gets or sets whether the Combobox is disabled."""
152        return self.combobox.config.disabled
153    
154    @disabled.setter
155    def disabled(self, value: bool) -> None:
156        self.combobox.config.disabled = value
157    
158    @property
159    def multiselection(self) -> bool:
160        """Gets or sets whether multiple selection is enabled."""
161        return self.combobox.config.multiselection
162    
163    @multiselection.setter
164    def multiselection(self, value: bool) -> None:
165        self.combobox.config.multiselection = value
166    
167    @property
168    def placeholder(self) -> str:
169        """Gets or sets the placeholder text."""
170        return self.combobox.config.placeholder
171    
172    @placeholder.setter
173    def placeholder(self, value: str) -> None:
174        self.combobox.config.placeholder = value
175    
176    @property
177    def read_only(self) -> bool:
178        """Gets or sets whether the Combobox is read-only."""
179        return self.combobox.config.readOnly
180    
181    @read_only.setter
182    def read_only(self, value: bool) -> None:
183        self.combobox.config.readOnly = value
184    
185    @property
186    def value(self) -> Union[str, int, List[Union[str, int]]]:
187        """Gets or sets the selected value(s) of the Combobox."""
188        return self.get_value()
189    
190    @value.setter
191    def value(self, ids: Union[str, int, List[Union[str, int]]]) -> None:
192        self.set_value(ids)
193    
194    # Add other properties similarly...
195    
196    # For properties that are functions or complex types, you may need to handle them differently
197    
198    @property
199    def filter(self) -> Callable[[Dict[str, Any], str], bool]:
200        """Gets or sets a custom function for filtering Combobox options."""
201        return self._filter_function
202    
203    @filter.setter
204    def filter(self, value: Callable[[Dict[str, Any], str], bool]) -> None:
205        self._filter_function = value
206        def js_filter(item, target):
207            return value(item.to_py(), target)
208        self.combobox.config.filter = create_proxy(js_filter)
209    
210    # For the 'template' property
211    @property
212    def template(self) -> Callable[[Any], str]:
213        """Gets or sets a template for displaying options."""
214        return self._template_function
215    
216    @template.setter
217    def template(self, value: Callable[[Any], str]) -> None:
218        self._template_function = value
219        self.combobox.config.template = create_proxy(value)
Combobox( config: ComboboxConfig = None, widget_parent: Any = None)
14    def __init__(self, config: ComboboxConfig = None, widget_parent: Any = None):
15        """Initializes the Combobox instance."""
16        if config is None:
17            config = ComboboxConfig()
18        config_dict = config.to_dict()
19        self.combobox = js.dhx.Combobox.new(widget_parent, js.JSON.parse(json.dumps(config_dict)))

Initializes the Combobox instance.

combobox

Combobox API Functions

def add_option(self, value: Union[Dict[str, Any], str], join: bool = True) -> None:
23    def add_option(self, value: Union[Dict[str, Any], str], join: bool = True) -> None:
24        """Adds a new item into the list of Combobox options."""
25        self.combobox.addOption(value, join)

Adds a new item into the list of Combobox options.

def blur(self) -> None:
27    def blur(self) -> None:
28        """Removes focus from Combobox."""
29        self.combobox.blur()

Removes focus from Combobox.

def clear(self) -> None:
31    def clear(self) -> None:
32        """Clears the value set in the Combobox."""
33        self.combobox.clear()

Clears the value set in the Combobox.

def destructor(self) -> None:
35    def destructor(self) -> None:
36        """Removes a Combobox instance and releases occupied resources."""
37        self.combobox.destructor()

Removes a Combobox instance and releases occupied resources.

def disable(self) -> None:
39    def disable(self) -> None:
40        """Disables Combobox on a page."""
41        self.combobox.disable()

Disables Combobox on a page.

def enable(self) -> None:
43    def enable(self) -> None:
44        """Enables a disabled Combobox."""
45        self.combobox.enable()

Enables a disabled Combobox.

def focus(self) -> None:
47    def focus(self) -> None:
48        """Sets focus in the input without opening a popup with options."""
49        self.combobox.focus()

Sets focus in the input without opening a popup with options.

def get_value(self, as_array: bool = False) -> Union[str, int, List[Union[str, int]]]:
51    def get_value(self, as_array: bool = False) -> Union[str, int, List[Union[str, int]]]:
52        """Gets id(s) of items from data collection selected in Combobox."""
53        return self.combobox.getValue(as_array)

Gets id(s) of items from data collection selected in Combobox.

def is_disabled(self) -> bool:
55    def is_disabled(self) -> bool:
56        """Checks whether a Combobox is disabled."""
57        return self.combobox.isDisabled()

Checks whether a Combobox is disabled.

def paint(self) -> None:
59    def paint(self) -> None:
60        """Repaints the Combobox."""
61        self.combobox.paint()

Repaints the Combobox.

def set_value(self, ids: Union[str, int, List[Union[str, int]]]) -> None:
63    def set_value(self, ids: Union[str, int, List[Union[str, int]]]) -> None:
64        """Selects option(s) in Combobox."""
65        self.combobox.setValue(ids)

Selects option(s) in Combobox.

def add_event_handler(self, event_name: str, handler: Callable) -> None:
69    def add_event_handler(self, event_name: str, handler: Callable) -> None:
70        """Helper to add event handlers dynamically."""
71        event_proxy = create_proxy(handler)
72        self.combobox.events.on(event_name, event_proxy)

Helper to add event handlers dynamically.

def on_after_close(self, handler: Callable[[], NoneType]) -> None:
74    def on_after_close(self, handler: Callable[[], None]) -> None:
75        """Fires after closing a list with options."""
76        self.add_event_handler('afterClose', handler)

Fires after closing a list with options.

def on_after_open(self, handler: Callable[[], NoneType]) -> None:
78    def on_after_open(self, handler: Callable[[], None]) -> None:
79        """Fires after opening a list with options."""
80        self.add_event_handler('afterOpen', handler)

Fires after opening a list with options.

def on_before_change( self, handler: Callable[[Union[str, int, List[Union[str, int]]]], Optional[bool]]) -> None:
82    def on_before_change(self, handler: Callable[[Union[str, int, List[Union[str, int]]]], Union[bool, None]]) -> None:
83        """Fires before selection of a new option."""
84        def event_handler(ids):
85            result = handler(ids)
86            if result is False:
87                return js.Boolean(False)
88        event_proxy = create_proxy(event_handler)
89        self.combobox.events.on('beforeChange', event_proxy)

Fires before selection of a new option.

def on_before_close(self, handler: Callable[[], Optional[bool]]) -> None:
91    def on_before_close(self, handler: Callable[[], Union[bool, None]]) -> None:
92        """Fires before closing a list with options."""
93        def event_handler():
94            result = handler()
95            if result is False:
96                return js.Boolean(False)
97        event_proxy = create_proxy(event_handler)
98        self.combobox.events.on('beforeClose', event_proxy)

Fires before closing a list with options.

def on_before_open(self, handler: Callable[[], Optional[bool]]) -> None:
100    def on_before_open(self, handler: Callable[[], Union[bool, None]]) -> None:
101        """Fires before opening a list with options."""
102        def event_handler():
103            result = handler()
104            if result is False:
105                return js.Boolean(False)
106        event_proxy = create_proxy(event_handler)
107        self.combobox.events.on('beforeOpen', event_proxy)

Fires before opening a list with options.

def on_blur(self, handler: Callable[[], NoneType]) -> None:
109    def on_blur(self, handler: Callable[[], None]) -> None:
110        """Fires when Combobox has lost focus."""
111        self.add_event_handler('blur', handler)

Fires when Combobox has lost focus.

def on_change( self, handler: Callable[[Union[str, int, List[Union[str, int]]]], NoneType]) -> None:
113    def on_change(self, handler: Callable[[Union[str, int, List[Union[str, int]]]], None]) -> None:
114        """Fires when a new option is selected."""
115        self.add_event_handler('change', handler)

Fires when a new option is selected.

def on_focus(self, handler: Callable[[], NoneType]) -> None:
117    def on_focus(self, handler: Callable[[], None]) -> None:
118        """Fires when Combobox has received focus."""
119        self.add_event_handler('focus', handler)

Fires when Combobox has received focus.

def on_input(self, handler: Callable[[str], NoneType]) -> None:
121    def on_input(self, handler: Callable[[str], None]) -> None:
122        """Fires on typing text in an input of Combobox."""
123        self.add_event_handler('input', handler)

Fires on typing text in an input of Combobox.

def on_keydown( self, handler: Callable[[Any, Union[str, int, NoneType]], NoneType]) -> None:
125    def on_keydown(self, handler: Callable[[Any, Union[str, int, None]], None]) -> None:
126        """Fires when any key is pressed and an option of Combobox is in focus."""
127        self.add_event_handler('keydown', handler)

Fires when any key is pressed and an option of Combobox is in focus.

css: str
131    @property
132    def css(self) -> str:
133        """Gets or sets the CSS classes for Combobox."""
134        return self.combobox.config.css

Gets or sets the CSS classes for Combobox.

data: List[Dict[str, Any]]
140    @property
141    def data(self) -> List[Dict[str, Any]]:
142        """Gets or sets the data objects for Combobox."""
143        return self.combobox.config.data

Gets or sets the data objects for Combobox.

disabled: bool
149    @property
150    def disabled(self) -> bool:
151        """Gets or sets whether the Combobox is disabled."""
152        return self.combobox.config.disabled

Gets or sets whether the Combobox is disabled.

multiselection: bool
158    @property
159    def multiselection(self) -> bool:
160        """Gets or sets whether multiple selection is enabled."""
161        return self.combobox.config.multiselection

Gets or sets whether multiple selection is enabled.

placeholder: str
167    @property
168    def placeholder(self) -> str:
169        """Gets or sets the placeholder text."""
170        return self.combobox.config.placeholder

Gets or sets the placeholder text.

read_only: bool
176    @property
177    def read_only(self) -> bool:
178        """Gets or sets whether the Combobox is read-only."""
179        return self.combobox.config.readOnly

Gets or sets whether the Combobox is read-only.

value: Union[str, int, List[Union[str, int]]]
185    @property
186    def value(self) -> Union[str, int, List[Union[str, int]]]:
187        """Gets or sets the selected value(s) of the Combobox."""
188        return self.get_value()

Gets or sets the selected value(s) of the Combobox.

filter: Callable[[Dict[str, Any], str], bool]
198    @property
199    def filter(self) -> Callable[[Dict[str, Any], str], bool]:
200        """Gets or sets a custom function for filtering Combobox options."""
201        return self._filter_function

Gets or sets a custom function for filtering Combobox options.

template: Callable[[Any], str]
211    @property
212    def template(self) -> Callable[[Any], str]:
213        """Gets or sets a template for displaying options."""
214        return self._template_function

Gets or sets a template for displaying options.

class ComboboxConfig:
  6class ComboboxConfig:
  7    """
  8    Configuration class for Combobox.
  9    """
 10    def __init__(self,
 11                 css: str = None,
 12                 data: List[Dict[str, Any]] = None,
 13                 disabled: bool = False,
 14                 eventHandlers: Dict[str, Dict[str, Callable[[Any, Union[str, int]], Union[bool, None]]]] = None,
 15                 filter: Callable[[Dict[str, Any], str], bool] = None,
 16                 helpMessage: str = None,
 17                 hiddenLabel: bool = False,
 18                 htmlEnable: bool = True,
 19                 itemHeight: Union[int, str] = 32,
 20                 itemsCount: Union[bool, Callable[[int], str]] = False,
 21                 label: str = None,
 22                 labelPosition: str = "top",
 23                 labelWidth: Union[str, int] = "auto",
 24                 listHeight: Union[int, str] = 224,
 25                 multiselection: bool = False,
 26                 newOptions: bool = False,
 27                 placeholder: str = None,
 28                 readOnly: bool = False,
 29                 selectAllButton: bool = False,
 30                 template: Callable[[Any], str] = None,
 31                 value: Union[str, int, List[Union[str, int]]] = None,
 32                 virtual: bool = False):
 33        """
 34        :param css: (Optional) Adds style classes to Combobox.
 35        :param data: (Optional) Specifies an array of data objects to set into the combobox.
 36        :param disabled: (Optional) Makes Combobox disabled.
 37        :param eventHandlers: (Optional) Adds event handlers to HTML elements of a custom template.
 38        :param filter: (Optional) Sets a custom function for filtering Combobox options.
 39        :param helpMessage: (Optional) Adds an icon with a question mark next to the Combo input.
 40        :param hiddenLabel: (Optional) Adds a hidden label for a Combo box input.
 41        :param htmlEnable: (Optional) Enables rendering of HTML content in options.
 42        :param itemHeight: (Optional) Sets the height of an item in the list of options.
 43        :param itemsCount: (Optional) Shows the total number of selected options.
 44        :param label: (Optional) Adds a label for Combobox.
 45        :param labelPosition: (Optional) Defines the position of a label.
 46        :param labelWidth: (Optional) Sets the width of a label.
 47        :param listHeight: (Optional) Sets the height of the list of options.
 48        :param multiselection: (Optional) Enables selection of multiple options.
 49        :param newOptions: (Optional) Allows users to add new options into the data collection.
 50        :param placeholder: (Optional) Sets a placeholder in the input of Combobox.
 51        :param readOnly: (Optional) Makes Combobox read-only.
 52        :param selectAllButton: (Optional) Defines whether the Select All button should be shown.
 53        :param template: (Optional) Sets a template for displaying options.
 54        :param value: (Optional) Specifies the values that will appear in the input on initialization.
 55        :param virtual: (Optional) Enables dynamic loading of data on scrolling the list of options.
 56        """
 57        self.css = css
 58        self.data = data if data else []
 59        self.disabled = disabled
 60        self.eventHandlers = eventHandlers
 61        self.filter = filter
 62        self.helpMessage = helpMessage
 63        self.hiddenLabel = hiddenLabel
 64        self.htmlEnable = htmlEnable
 65        self.itemHeight = itemHeight
 66        self.itemsCount = itemsCount
 67        self.label = label
 68        self.labelPosition = labelPosition
 69        self.labelWidth = labelWidth
 70        self.listHeight = listHeight
 71        self.multiselection = multiselection
 72        self.newOptions = newOptions
 73        self.placeholder = placeholder
 74        self.readOnly = readOnly
 75        self.selectAllButton = selectAllButton
 76        self.template = template
 77        self.value = value
 78        self.virtual = virtual
 79    
 80    def to_dict(self) -> Dict[str, Any]:
 81        """
 82        Converts the ComboboxConfig into a dictionary format that can be
 83        passed into the combobox constructor.
 84        """
 85        config_dict = {
 86            'css': self.css,
 87            'data': self.data,
 88            'disabled': self.disabled,
 89            'helpMessage': self.helpMessage,
 90            'hiddenLabel': self.hiddenLabel,
 91            'htmlEnable': self.htmlEnable,
 92            'itemHeight': self.itemHeight,
 93            'itemsCount': self.itemsCount,
 94            'label': self.label,
 95            'labelPosition': self.labelPosition,
 96            'labelWidth': self.labelWidth,
 97            'listHeight': self.listHeight,
 98            'multiselection': self.multiselection,
 99            'newOptions': self.newOptions,
100            'placeholder': self.placeholder,
101            'readOnly': self.readOnly,
102            'selectAllButton': self.selectAllButton,
103            'value': self.value,
104            'virtual': self.virtual
105        }
106        # Remove None values
107        config_dict = {k: v for k, v in config_dict.items() if v is not None}
108        
109        # Handle eventHandlers separately
110        if self.eventHandlers:
111            # Convert Python functions to JavaScript proxies
112            handlers = {}
113            for event_name, classes in self.eventHandlers.items():
114                handlers[event_name] = {}
115                for class_name, func in classes.items():
116                    handlers[event_name][class_name] = create_proxy(func)
117            config_dict['eventHandlers'] = handlers
118        
119        # Handle filter function
120        if self.filter:
121            config_dict['filter'] = create_proxy(self.filter)
122        
123        # Handle template function
124        if self.template:
125            config_dict['template'] = create_proxy(self.template)
126        
127        return config_dict

Configuration class for Combobox.

ComboboxConfig( css: str = None, data: List[Dict[str, Any]] = None, disabled: bool = False, eventHandlers: Dict[str, Dict[str, Callable[[Any, Union[str, int]], Optional[bool]]]] = None, filter: Callable[[Dict[str, Any], str], bool] = None, helpMessage: str = None, hiddenLabel: bool = False, htmlEnable: bool = True, itemHeight: Union[int, str] = 32, itemsCount: Union[bool, Callable[[int], str]] = False, label: str = None, labelPosition: str = 'top', labelWidth: Union[str, int] = 'auto', listHeight: Union[int, str] = 224, multiselection: bool = False, newOptions: bool = False, placeholder: str = None, readOnly: bool = False, selectAllButton: bool = False, template: Callable[[Any], str] = None, value: Union[str, int, List[Union[str, int]]] = None, virtual: bool = False)
10    def __init__(self,
11                 css: str = None,
12                 data: List[Dict[str, Any]] = None,
13                 disabled: bool = False,
14                 eventHandlers: Dict[str, Dict[str, Callable[[Any, Union[str, int]], Union[bool, None]]]] = None,
15                 filter: Callable[[Dict[str, Any], str], bool] = None,
16                 helpMessage: str = None,
17                 hiddenLabel: bool = False,
18                 htmlEnable: bool = True,
19                 itemHeight: Union[int, str] = 32,
20                 itemsCount: Union[bool, Callable[[int], str]] = False,
21                 label: str = None,
22                 labelPosition: str = "top",
23                 labelWidth: Union[str, int] = "auto",
24                 listHeight: Union[int, str] = 224,
25                 multiselection: bool = False,
26                 newOptions: bool = False,
27                 placeholder: str = None,
28                 readOnly: bool = False,
29                 selectAllButton: bool = False,
30                 template: Callable[[Any], str] = None,
31                 value: Union[str, int, List[Union[str, int]]] = None,
32                 virtual: bool = False):
33        """
34        :param css: (Optional) Adds style classes to Combobox.
35        :param data: (Optional) Specifies an array of data objects to set into the combobox.
36        :param disabled: (Optional) Makes Combobox disabled.
37        :param eventHandlers: (Optional) Adds event handlers to HTML elements of a custom template.
38        :param filter: (Optional) Sets a custom function for filtering Combobox options.
39        :param helpMessage: (Optional) Adds an icon with a question mark next to the Combo input.
40        :param hiddenLabel: (Optional) Adds a hidden label for a Combo box input.
41        :param htmlEnable: (Optional) Enables rendering of HTML content in options.
42        :param itemHeight: (Optional) Sets the height of an item in the list of options.
43        :param itemsCount: (Optional) Shows the total number of selected options.
44        :param label: (Optional) Adds a label for Combobox.
45        :param labelPosition: (Optional) Defines the position of a label.
46        :param labelWidth: (Optional) Sets the width of a label.
47        :param listHeight: (Optional) Sets the height of the list of options.
48        :param multiselection: (Optional) Enables selection of multiple options.
49        :param newOptions: (Optional) Allows users to add new options into the data collection.
50        :param placeholder: (Optional) Sets a placeholder in the input of Combobox.
51        :param readOnly: (Optional) Makes Combobox read-only.
52        :param selectAllButton: (Optional) Defines whether the Select All button should be shown.
53        :param template: (Optional) Sets a template for displaying options.
54        :param value: (Optional) Specifies the values that will appear in the input on initialization.
55        :param virtual: (Optional) Enables dynamic loading of data on scrolling the list of options.
56        """
57        self.css = css
58        self.data = data if data else []
59        self.disabled = disabled
60        self.eventHandlers = eventHandlers
61        self.filter = filter
62        self.helpMessage = helpMessage
63        self.hiddenLabel = hiddenLabel
64        self.htmlEnable = htmlEnable
65        self.itemHeight = itemHeight
66        self.itemsCount = itemsCount
67        self.label = label
68        self.labelPosition = labelPosition
69        self.labelWidth = labelWidth
70        self.listHeight = listHeight
71        self.multiselection = multiselection
72        self.newOptions = newOptions
73        self.placeholder = placeholder
74        self.readOnly = readOnly
75        self.selectAllButton = selectAllButton
76        self.template = template
77        self.value = value
78        self.virtual = virtual
Parameters
  • css: (Optional) Adds style classes to Combobox.
  • data: (Optional) Specifies an array of data objects to set into the combobox.
  • disabled: (Optional) Makes Combobox disabled.
  • eventHandlers: (Optional) Adds event handlers to HTML elements of a custom template.
  • filter: (Optional) Sets a custom function for filtering Combobox options.
  • helpMessage: (Optional) Adds an icon with a question mark next to the Combo input.
  • hiddenLabel: (Optional) Adds a hidden label for a Combo box input.
  • htmlEnable: (Optional) Enables rendering of HTML content in options.
  • itemHeight: (Optional) Sets the height of an item in the list of options.
  • itemsCount: (Optional) Shows the total number of selected options.
  • label: (Optional) Adds a label for Combobox.
  • labelPosition: (Optional) Defines the position of a label.
  • labelWidth: (Optional) Sets the width of a label.
  • listHeight: (Optional) Sets the height of the list of options.
  • multiselection: (Optional) Enables selection of multiple options.
  • newOptions: (Optional) Allows users to add new options into the data collection.
  • placeholder: (Optional) Sets a placeholder in the input of Combobox.
  • readOnly: (Optional) Makes Combobox read-only.
  • selectAllButton: (Optional) Defines whether the Select All button should be shown.
  • template: (Optional) Sets a template for displaying options.
  • value: (Optional) Specifies the values that will appear in the input on initialization.
  • virtual: (Optional) Enables dynamic loading of data on scrolling the list of options.
css
data
disabled
eventHandlers
filter
helpMessage
hiddenLabel
htmlEnable
itemHeight
itemsCount
label
labelPosition
labelWidth
listHeight
multiselection
newOptions
placeholder
readOnly
selectAllButton
template
value
virtual
def to_dict(self) -> Dict[str, Any]:
 80    def to_dict(self) -> Dict[str, Any]:
 81        """
 82        Converts the ComboboxConfig into a dictionary format that can be
 83        passed into the combobox constructor.
 84        """
 85        config_dict = {
 86            'css': self.css,
 87            'data': self.data,
 88            'disabled': self.disabled,
 89            'helpMessage': self.helpMessage,
 90            'hiddenLabel': self.hiddenLabel,
 91            'htmlEnable': self.htmlEnable,
 92            'itemHeight': self.itemHeight,
 93            'itemsCount': self.itemsCount,
 94            'label': self.label,
 95            'labelPosition': self.labelPosition,
 96            'labelWidth': self.labelWidth,
 97            'listHeight': self.listHeight,
 98            'multiselection': self.multiselection,
 99            'newOptions': self.newOptions,
100            'placeholder': self.placeholder,
101            'readOnly': self.readOnly,
102            'selectAllButton': self.selectAllButton,
103            'value': self.value,
104            'virtual': self.virtual
105        }
106        # Remove None values
107        config_dict = {k: v for k, v in config_dict.items() if v is not None}
108        
109        # Handle eventHandlers separately
110        if self.eventHandlers:
111            # Convert Python functions to JavaScript proxies
112            handlers = {}
113            for event_name, classes in self.eventHandlers.items():
114                handlers[event_name] = {}
115                for class_name, func in classes.items():
116                    handlers[event_name][class_name] = create_proxy(func)
117            config_dict['eventHandlers'] = handlers
118        
119        # Handle filter function
120        if self.filter:
121            config_dict['filter'] = create_proxy(self.filter)
122        
123        # Handle template function
124        if self.template:
125            config_dict['template'] = create_proxy(self.template)
126        
127        return config_dict

Converts the ComboboxConfig into a dictionary format that can be passed into the combobox constructor.