Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ def select_field(
)


def demo_form(id_prefix: str = "", **props) -> rx.Component:
def demo_form(
id_prefix: str = "",
on_submit: EventType[dict[str, Any]] | None = None,
**props,
) -> rx.Component:
"""Create and return the demo form component.

Builds a complete form with all required fields, validation,
Expand All @@ -279,13 +283,17 @@ def demo_form(id_prefix: str = "", **props) -> rx.Component:
Args:
id_prefix: Optional prefix for all element IDs to ensure uniqueness when multiple forms exist.
If empty, a unique prefix will be auto-generated.
on_submit: Additional event handler(s) appended after the built-in submit handlers (PostHog tracking + dialog close).
**props: Additional properties to pass to the form component

Returns:
A Reflex form component with all demo form fields
"""
prefix = id_prefix or get_unique_variable_name()
email_id = f"{prefix}_user_email"
extra_on_submit = (
on_submit if isinstance(on_submit, list) else [on_submit] if on_submit else []
)
Comment on lines +294 to +296
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 isinstance check doesn't handle tuple event-handler lists

Reflex allows event handler collections to be passed as either a list or a tuple. If a caller passes on_submit as a tuple (e.g., on_submit=(HandlerA, HandlerB)), isinstance(on_submit, list) returns False, so the entire tuple is wrapped in another list as a single element — meaning *extra_on_submit spreads (HandlerA, HandlerB) as one item instead of two separate handlers. Reflex would then try to interpret the tuple as a single handler and likely raise a runtime error or silently ignore it.

Suggested change
extra_on_submit = (
on_submit if isinstance(on_submit, list) else [on_submit] if on_submit else []
)
extra_on_submit = (
list(on_submit)
if isinstance(on_submit, (list, tuple))
else [on_submit]
if on_submit
else []
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tuples aren't accepted as part of that type, right?

form = rx.el.form(
rx.el.div(
input_field("First name", "John", "first_name", "text", True),
Expand Down Expand Up @@ -367,6 +375,7 @@ def demo_form(id_prefix: str = "", **props) -> rx.Component:
on_submit=[
DemoFormStateUI.track_demo_form_posthog,
rx.call_function(demo_form_open_cs.set_value(False)),
*extra_on_submit,
],
data_default_form_id="965991",
**props,
Expand All @@ -377,13 +386,17 @@ def demo_form(id_prefix: str = "", **props) -> rx.Component:


def demo_form_dialog(
trigger: rx.Component | None = None, id_prefix: str = "", **props
trigger: rx.Component | None = None,
id_prefix: str = "",
on_submit: EventType[dict[str, Any]] | None = None,
**props,
) -> rx.Component:
"""Return a demo form dialog container element.

Args:
trigger: The component that triggers the dialog
id_prefix: Optional prefix for all element IDs to ensure uniqueness when multiple dialogs exist
on_submit: Additional event handler(s) forwarded to the inner demo form's on_submit.
**props: Additional properties to pass to the dialog root

Returns:
Expand Down Expand Up @@ -413,7 +426,11 @@ def demo_form_dialog(
),
class_name="flex flex-row justify-between items-center gap-1 px-6 pt-4 -mb-4",
),
demo_form(id_prefix=id_prefix, class_name="w-full max-w-md"),
demo_form(
id_prefix=id_prefix,
on_submit=on_submit,
class_name="w-full max-w-md",
),
class_name="relative isolate overflow-hidden -m-px w-full max-w-md",
),
class_name="h-fit mt-1 overflow-hidden w-full max-w-md",
Expand Down
Loading