MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / radio

Function radio

pywebio/input.py:414–444  ·  view source on GitHub ↗

r"""A group of radio button. Only a single button can be selected. :param list options: List of options. The format is the same as the ``options`` parameter of the `select()` function :param bool inline: Whether to display the options on one line. Default is ``False`` :param str value:

(label: str = '', options: List[Union[Dict[str, Any], Tuple, List, str]] = None, *, inline: bool = None,
          validate: Callable[[Any], Optional[str]] = None,
          name: str = None, value: str = None, onchange: Callable[[Any], None] = None, required: bool = None,
          help_text: str = None, **other_html_attrs)

Source from the content-addressed store, hash-verified

412
413
414def radio(label: str = '', options: List[Union[Dict[str, Any], Tuple, List, str]] = None, *, inline: bool = None,
415 validate: Callable[[Any], Optional[str]] = None,
416 name: str = None, value: str = None, onchange: Callable[[Any], None] = None, required: bool = None,
417 help_text: str = None, **other_html_attrs):
418 r"""A group of radio button. Only a single button can be selected.
419
420 :param list options: List of options. The format is the same as the ``options`` parameter of the `select()` function
421 :param bool inline: Whether to display the options on one line. Default is ``False``
422 :param str value: The value of the initial selected items.
423 You can also set the initial selected option by setting the ``selected`` field in the ``options`` list item.
424 :param bool required: whether to must select one option. (the user can select nothing option by default)
425 :param - label, validate, name, onchange, help_text, other_html_attrs: Those arguments have the same meaning as for `input()`
426 :return: The value of the option selected by the user, if the user does not select any value, return ``None``
427 """
428 assert options is not None, 'Required `options` parameter in radio()'
429
430 item_spec, valid_func, onchange_func = _parse_args(locals())
431 item_spec['options'] = _parse_select_options(options)
432 if value is not None:
433 del item_spec['value']
434 item_spec['options'] = _set_options_selected(item_spec['options'], value)
435
436 # From https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required
437 # In the case of a same named group of radio buttons, if a single radio button in the group has the required attribute,
438 # a radio button in that group must be checked, although it doesn't have to be the one with the attribute is applied
439 if required is not None:
440 del item_spec['required']
441 item_spec['options'][-1]['required'] = required
442 item_spec['type'] = RADIO
443
444 return single_input(item_spec, valid_func, lambda d: d, onchange_func)
445
446
447def _parse_action_buttons(buttons):

Callers 3

put_radioFunction · 0.90
basic_inputFunction · 0.85
formFunction · 0.85

Calls 4

_parse_argsFunction · 0.85
_parse_select_optionsFunction · 0.85
_set_options_selectedFunction · 0.85
single_inputFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…