Skip to content

TextInput

Bases: InputElement

_value_type: type property

Get the TextInput value type: string str.

__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, max_chars=None, placeholder=None, multiline=False)

A simple text field.

Parameters:

Name Type Description Default
key str

ID of the element. It must be unique as it is the key used to story data in Project(), otherwise it will lead to conflicts at runtime in both execution and Streamlit modes. The key will be transformed into snake case and slugified to avoid any special character or whitespace. Note that an ID cannot start with _. Try to choose a key that is meaningful for your context (see examples projects).

required
value Optional[Union[str, List[str]]]

Initial text value.

required
label Optional[str]

Label to display next to the checkbox.

None
count Optional[Union[int, str]]

Specify the number of occurence of the widget. OneCode typically uses it for the streamlit case. Note that if count is defined, the expected value should always be a list, even if the count is 1. count can either be a fixed number (e.g. 3) or an expression dependent of other elements (see Using Expressions for more information).

None
optional Union[bool, str]

Specify whether the value may be None. optional can either be a fixed boolean (False or True) or a conditional expression dependent of other elements (see Using Expressions for more information).

False
hide_when_disabled bool

If element is optional, set it to True to hide it from the interface, otherwise it will be shown disabled.

False
max_chars int

Maximum number of characters allowed for this text field.

None
placeholder str

Placeholder text shown whenever there is no value.

None
multiline Union[bool, int]

Set to True or a height in pixels to make it multiline text area.

False

Raises:

Type Description
ValueError

if the key is empty or starts with _.

AttributeError

if one the kwargs conflicts with an existing attribute or method.

Example

from onecode import text_input, Mode, Project

Project().mode = Mode.EXECUTE
widget = text_input(
    key="TextInput",
    value="OneCode rocks!",
    label="My TextInput"
)
print(widget)
Output
"OneCode rocks!"

_validate(value)

No validation is performed.

streamlit(id)

Returns:

Type Description
str

The Streamlit code for a text input field (st.text).