Form#

class marimo.ui.form(element: UIElement[S, T], *, 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()
# 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 clicked

  • element: a copy of the wrapped element

Initialization Args.

  • element: the element to wrap

  • label: text label for the form

  • on_change: optional callback to run when this element’s value changes

Public methods

Inherited from UIElement

form([label])

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.

Public Data Attributes:

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.