Skip to content

ui.form to have an option to stop execution of dependent cells if button not pressed #8336

@petern3

Description

@petern3

Description

I have a form at the top of my notebook that is referenced in various places throughout the notebook. My two options are currently:

  • Reference input_form.value["key"] and have "errors" throughout the code until the button is pressed.
  • In every cell that uses the form, also have mo.stop(input_form.value is None, "Please complete form") beforehand, which is slightly cumbersome.

It would be good if there was a way to configure the form so that it skips the dependent cells automatically.

If I were writing only a couple of apps then it wouldn't be a problem. But we're likely going to have hundreds, all with a similar form at the top.

Suggested solution

Ideally this could be configured from mo.ui.form(...):

  • With a stop_cell_execution: bool = False argument. The 'stop' message could be based on the label.
  • With a stop_cell_execution_message: str | None = None argument that if a string, stops execution.
  • Or with both.
  • (Or maybe this could even be the default?)

Are you willing to submit a PR?

  • Yes

Alternatives

I've tried wrapping the form.

class InputGetter:
    def __init__(self, ui_element: mo.ui.form):
        self.ui_element = ui_element

    @property
    def value(self) -> dict[str, Any]:
        mo.stop(self.ui_element.value is None, self.msg)
        assert self.ui_element.value is not None
        return self.ui_element.value

This does wonders for the output of the downstream cells. But Marimo loses the reference, and doesn't know to make downstream cells stale when the form is submitted.

Thanks!

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions