Skip to content

FormPanel

Base classes

Name Children Inherits
Vertical
textual.containers
An expanding container with vertical layout and no scrollbars.

⋔ Inheritance diagram

graph TD
  3587099367["view.FormPanel"]
  723859837["containers.Vertical"]
  4188532303["widget.Widget"]
  3946681048["dom.DOMNode"]
  53685856["message_pump.MessagePump"]
  2751680898["builtins.object"]
  723859837 --> 3587099367
  4188532303 --> 723859837
  3946681048 --> 4188532303
  53685856 --> 3946681048
  2751680898 --> 53685856

🛈 DocStrings

Bases: Vertical

A titled :class:FormView with Submit / Cancel buttons.

Source code in src/promptantic/textual/view.py
class FormPanel(Vertical):
    """A titled :class:`FormView` with Submit / Cancel buttons."""

    DEFAULT_CSS = """
    FormPanel { height: auto; }
    FormPanel > #pa-title { text-style: bold; margin: 0 0 1 0; }
    FormPanel > #pa-buttons { height: auto; margin: 1 0 0 0; }
    FormPanel > #pa-buttons Button { margin: 0 1 0 0; }
    """

    def __init__(
        self, target: FormTarget[Any], *, title: str | None, initial: Mapping[str, Any] | None
    ) -> None:
        super().__init__()
        self.form = FormView(target, initial=initial)
        self.title_text = title or target.title

    def compose(self) -> ComposeResult:
        if self.title_text:
            yield Label(self.title_text, id="pa-title")
        yield self.form
        with Horizontal(id="pa-buttons"):
            yield Button("Submit", variant="primary", id="pa-submit")
            yield Button("Cancel", id="pa-cancel")

    def on_button_pressed(self, event: Button.Pressed) -> None:
        event.stop()
        if event.button.id == "pa-submit":
            self.form.submit()
        elif event.button.id == "pa-cancel":
            self.form.cancel()

:fa-brands-github: Show source on GitHub