Form#
- class marimo.ui.form(element: UIElement[S, T], *, bordered: bool = True, loading: bool = False, submit_button_label: str = 'Submit', submit_button_tooltip: str | None = None, submit_button_disabled: bool = False, clear_on_submit: bool = False, show_clear_button: bool = False, clear_button_label: str = 'Clear', clear_button_tooltip: str | None = None, validate: Callable[[Mapping[str, Mapping[str, JSONType] | Sequence[JSONType] | str | int | float | bool | MIME | None] | Sequence[Mapping[str, JSONType] | Sequence[JSONType] | str | int | float | bool | MIME | None] | str | int | float | bool | MIME | None], str | None] | None = None, label: str = '', on_change: Callable[[T | None], None] | None = None)#
A submittable form linked to a UIElement.
Use a
form
to prevent sending UI element values to Python until a button is clicked.The value of a
form
is the value of the underlying element the last time the form was submitted.Example.
# Create a form with chaining form = mo.ui.slider(1, 100).form()
# Create a form with multiple elements form = mo.md(''' **Your form.** {name} {date} ''').batch( name=mo.ui.text(label='name'), date=mo.ui.date(label='date'), ).form(show_clear_button=True, bordered=False)
# Instantiate a form directly form = mo.ui.form(element=mo.ui.slider(1, 100))
Attributes.
value
: the value of the wrapped element when the form’s submit button was last clickedelement
: a copy of the wrapped element
Initialization Args.
element
: the element to wrapbordered
: whether the form should have a borderloading
: whether the form should be in a loading statesubmit_button_label
: the label of the submit buttonsubmit_button_tooltip
: the tooltip of the submit buttonsubmit_button_disabled
: whether the submit button should be disabledclear_on_submit
: whether the form should clear its contents after submittingshow_clear_button
: whether the form should show a clear buttonclear_button_label
: the label of the clear buttonclear_button_tooltip
: the tooltip of the clear buttonvalidate
: a function that takes the form’s value and returns an error message if the value is invalid, orNone
if the value is validlabel
: text label for the formon_change
: optional callback to run when this element’s value changes
Public methods
Inherited from
UIElement
form
([label, bordered, loading, ...])Create a submittable form out of this
UIElement
.Inherited from
Html
batch
(**elements)Convert an HTML object with templated text into a UI element.
center
()Center an item.
right
()Right-justify.
left
()Left-justify.
callout
([kind])Create a callout containing this HTML element.
style
(style)Wrap an object in a styled container.
Public Data Attributes:
Inherited from
UIElement
value
The element’s current value.
Inherited from
Html
text
A string of HTML representing this element.