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

Function input

pywebio/input.py:137–268  ·  view source on GitHub ↗

r"""Text input :param str label: Label of input field. :param str type: Input type. Currently, supported types are:`TEXT` , `NUMBER` , `FLOAT` , `PASSWORD` , `URL` , `DATE` , `TIME`, `DATETIME`, `COLOR` The value of `DATE` , `TIME`, `DATETIME` type is a string in the format of `YYYY

(label: str = '', type: str = TEXT, *, validate: Callable[[Any], Optional[str]] = None, name: str = None,
          value: Union[str, int] = None,
          action: Tuple[str, Callable[[Callable], None]] = None, onchange: Callable[[Any], None] = None,
          placeholder: str = None, required: bool = None,
          readonly: bool = None, datalist: List[str] = None, help_text: str = None, **other_html_attrs)

Source from the content-addressed store, hash-verified

135
136
137def input(label: str = '', type: str = TEXT, *, validate: Callable[[Any], Optional[str]] = None, name: str = None,
138 value: Union[str, int] = None,
139 action: Tuple[str, Callable[[Callable], None]] = None, onchange: Callable[[Any], None] = None,
140 placeholder: str = None, required: bool = None,
141 readonly: bool = None, datalist: List[str] = None, help_text: str = None, **other_html_attrs):
142 r"""Text input
143
144 :param str label: Label of input field.
145 :param str type: Input type. Currently, supported types are:`TEXT` , `NUMBER` , `FLOAT` , `PASSWORD` , `URL` , `DATE` , `TIME`, `DATETIME`, `COLOR`
146
147 The value of `DATE` , `TIME`, `DATETIME` type is a string in the format of `YYYY-MM-DD` , `HH:MM:SS` , `YYYY-MM-DDTHH:MM` respectively
148 (`%Y-%m-%d`, `%H:%M:%S`, `%Y-%m-%dT%H:%M` in python `strptime() <https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior>`_ format).
149 :param callable validate: Input value validation function. If provided, the validation function will be called when
150 user completes the input field or submits the form.
151
152 ``validate`` receives the input value as a parameter. When the input value is valid, it returns ``None``.
153 When the input value is invalid, it returns an error message string.
154
155 For example:
156
157 .. exportable-codeblock::
158 :name: input-valid-func
159 :summary: `input()` validation
160
161 def check_age(age):
162 if age>30:
163 return 'Too old'
164 elif age<10:
165 return 'Too young'
166 input('Input your age', type=NUMBER, validate=check_age)
167
168 :param str name: A string specifying a name for the input. Used with `input_group()` to identify different input
169 items in the results of the input group. If call the input function alone, this parameter can **not** be set!
170 :param str value: The initial value of the input
171 :type action: tuple(label:str, callback:callable)
172 :param action: Put a button on the right side of the input field, and user can click the button to set the value for the input.
173
174 ``label`` is the label of the button, and ``callback`` is the callback function to set the input value when clicked.
175
176 The callback is invoked with one argument, the ``set_value``. ``set_value`` is a callable object, which is
177 invoked with one or two arguments. You can use ``set_value`` to set the value for the input.
178
179 ``set_value`` can be invoked with one argument: ``set_value(value:str)``. The ``value`` parameter is the value to be set for the input.
180
181 ``set_value`` can be invoked with two arguments: ``set_value(value:any, label:str)``. Each arguments are described as follows:
182
183 * ``value`` : The real value of the input, can be any object. it will not be passed to the user browser.
184 * ``label`` : The text displayed to the user
185
186 When calling ``set_value`` with two arguments, the input item in web page will become read-only.
187
188 The usage scenario of ``set_value(value:any, label:str)`` is: You need to dynamically generate the value of the
189 input in the callback, and hope that the result displayed to the user is different from the actual submitted data
190 (for example, result displayed to the user can be some user-friendly texts, and the value of the input can be
191 objects that are easier to process)
192
193 Usage example:
194

Callers 15

put_inputFunction · 0.90
targetFunction · 0.85
run_testFunction · 0.85
basic_inputFunction · 0.85
backgroundFunction · 0.85
background_inputFunction · 0.85
coro_background_inputFunction · 0.85
get_openai_configFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 6

_parse_argsFunction · 0.85
get_current_task_idFunction · 0.85
SetterClass · 0.85
output_register_callbackFunction · 0.85
single_inputFunction · 0.85
callbackFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…