Skip to main content

mo.ui.form

Wrap UI elements to create a form that only updates when submitted.

Overview

Forms prevent UI elements from triggering reactivity on every change. Instead, values are only sent when the form is submitted.

Usage

form = mo.ui.form(ui_element)
Or use the form() method on any UI element:
ui_element.form()

Examples

import marimo as mo

# Basic form
name_form = mo.ui.text(placeholder="Enter name").form()
name_form
# Form with multiple elements
form = mo.md(
    f"""
    **User Registration**
    
    Name: {mo.ui.text(placeholder="Full name")}
    Email: {mo.ui.text(kind="email")}
    Age: {mo.ui.number(start=18, stop=120)}
    """
).batch().form()

form
# Access submitted values
if form.value:
    mo.md(f"Submitted: {form.value}")
# Form with submit button label
form = mo.ui.text().form(submit_button_label="Search")

Form Behavior

  • Values don’t update until form is submitted
  • Submit button appears automatically
  • Form can be submitted by clicking button or pressing Enter
  • form.value is None until first submission
Use forms to batch multiple input changes together, reducing unnecessary computation.

Batch

Combine multiple UI elements

Interactive Elements

Guide to UI elements