r"""Drop-down selection By default, only one option can be selected at a time, you can set ``multiple`` parameter to enable multiple selection. :param list options: list of options. The available formats of the list items are: * dict:: { "label":(str)
(label: str = '', options: List[Union[Dict[str, Any], Tuple, List, str]] = None, *, multiple: bool = None,
validate: Callable[[Any], Optional[str]] = None, name: str = None, value: Union[List, str] = None,
onchange: Callable[[Any], None] = None, native: bool = True, required: bool = None, help_text: str = None,
**other_html_attrs)
| 339 | |
| 340 | |
| 341 | def select(label: str = '', options: List[Union[Dict[str, Any], Tuple, List, str]] = None, *, multiple: bool = None, |
| 342 | validate: Callable[[Any], Optional[str]] = None, name: str = None, value: Union[List, str] = None, |
| 343 | onchange: Callable[[Any], None] = None, native: bool = True, required: bool = None, help_text: str = None, |
| 344 | **other_html_attrs): |
| 345 | r"""Drop-down selection |
| 346 | |
| 347 | By default, only one option can be selected at a time, you can set ``multiple`` parameter to enable multiple selection. |
| 348 | |
| 349 | :param list options: list of options. The available formats of the list items are: |
| 350 | |
| 351 | * dict:: |
| 352 | |
| 353 | { |
| 354 | "label":(str) option label, |
| 355 | "value":(object) option value, |
| 356 | "selected":(bool, optional) whether the option is initially selected, |
| 357 | "disabled":(bool, optional) whether the option is initially disabled |
| 358 | } |
| 359 | |
| 360 | * tuple or list: ``(label, value, [selected,] [disabled])`` |
| 361 | * single value: label and value of option use the same value |
| 362 | |
| 363 | Attention: |
| 364 | |
| 365 | 1. The ``value`` of option can be any JSON serializable object |
| 366 | 2. If the ``multiple`` is not ``True``, the list of options can only have one ``selected`` item at most. |
| 367 | |
| 368 | :param bool multiple: whether multiple options can be selected |
| 369 | :param value: The value of the initial selected item. When ``multiple=True``, ``value`` must be a list. |
| 370 | You can also set the initial selected option by setting the ``selected`` field in the ``options`` list item. |
| 371 | :type value: list or str |
| 372 | :param bool required: Whether to select at least one item, only available when ``multiple=True`` |
| 373 | :param bool native: Using browser's native select component rather than |
| 374 | `bootstrap-select <https://github.com/snapappointments/bootstrap-select>`_. This is the default behavior. |
| 375 | :param - label, validate, name, onchange, help_text, other_html_attrs: Those arguments have the same meaning as for `input()` |
| 376 | :return: If ``multiple=True``, return a list of the values in the ``options`` selected by the user; |
| 377 | otherwise, return the single value selected by the user. |
| 378 | """ |
| 379 | assert options is not None, 'Required `options` parameter in select()' |
| 380 | |
| 381 | item_spec, valid_func, onchange_func = _parse_args(locals(), excludes=['value']) |
| 382 | item_spec['options'] = _parse_select_options(options) |
| 383 | if value is not None: |
| 384 | item_spec['options'] = _set_options_selected(item_spec['options'], value) |
| 385 | item_spec['type'] = SELECT |
| 386 | |
| 387 | return single_input(item_spec, valid_func=valid_func, preprocess_func=lambda d: d, onchange_func=onchange_func) |
| 388 | |
| 389 | |
| 390 | def checkbox(label: str = '', options: List[Union[Dict[str, Any], Tuple, List, str]] = None, *, inline: bool = None, |
no test coverage detected
searching dependent graphs…