Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pyi_hashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"reflex/components/el/element.pyi": "7faa2cda13a04870d6c1cbfb4b3a2a0a",
"reflex/components/el/elements/__init__.pyi": "2e30624329b8b535dfd8969f95efdd25",
"reflex/components/el/elements/base.pyi": "3fde62b5c749a40c43d1a4f0d0dccda4",
"reflex/components/el/elements/forms.pyi": "b7db5e64a2d0ee1a7ecf72cac927587a",
"reflex/components/el/elements/forms.pyi": "a316bdcc4bef4adb71d059057c6ffeff",
"reflex/components/el/elements/inline.pyi": "027f051369a253446365e77a4d621013",
"reflex/components/el/elements/media.pyi": "57bf44d696132478da377dd8d78807e2",
"reflex/components/el/elements/metadata.pyi": "23ad6217eb96f622b33a1f550c510cd5",
Expand Down
24 changes: 4 additions & 20 deletions reflex/components/el/elements/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
from reflex.components.tags.tag import Tag
from reflex.constants import Dirs, EventTriggers
from reflex.event import (
FORM_DATA,
EventChain,
EventHandler,
checked_input_event,
float_input_event,
input_event,
int_input_event,
key_event,
on_submit_event,
on_submit_string_event,
prevent_default,
)
from reflex.utils.imports import ImportDict
Expand All @@ -28,7 +31,6 @@

from .base import BaseHTML

FORM_DATA = Var(_js_expr="form_data")
HANDLE_SUBMIT_JS_JINJA2 = Environment().from_string(
"""
const handleSubmit_{{ handle_submit_unique_name }} = useCallback((ev) => {
Expand Down Expand Up @@ -110,24 +112,6 @@ class Fieldset(Element):
name: Var[str]


def on_submit_event_spec() -> tuple[Var[dict[str, Any]]]:
"""Event handler spec for the on_submit event.

Returns:
The event handler spec.
"""
return (FORM_DATA,)


def on_submit_string_event_spec() -> tuple[Var[dict[str, str]]]:
"""Event handler spec for the on_submit event.

Returns:
The event handler spec.
"""
return (FORM_DATA,)


class Form(BaseHTML):
"""Display the form element."""

Expand Down Expand Up @@ -167,7 +151,7 @@ class Form(BaseHTML):
handle_submit_unique_name: Var[str]

# Fired when the form is submitted
on_submit: EventHandler[on_submit_event_spec, on_submit_string_event_spec]
on_submit: EventHandler[on_submit_event, on_submit_string_event]

@classmethod
def create(cls, *children, **props):
Expand Down
24 changes: 24 additions & 0 deletions reflex/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,27 @@ def checked_input_event(e: ObjectVar[JavascriptInputEvent]) -> tuple[Var[bool]]:
return (e.target.checked,)


FORM_DATA = Var(_js_expr="form_data")


def on_submit_event() -> tuple[Var[dict[str, Any]]]:
"""Event handler spec for the on_submit event.

Returns:
The event handler spec.
"""
return (FORM_DATA,)


def on_submit_string_event() -> tuple[Var[dict[str, str]]]:
"""Event handler spec for the on_submit event.

Returns:
The event handler spec.
"""
return (FORM_DATA,)


class KeyInputInfo(TypedDict):
"""Information about a key input event."""

Expand Down Expand Up @@ -2224,6 +2245,7 @@ class EventNamespace:
# Constants
BACKGROUND_TASK_MARKER = BACKGROUND_TASK_MARKER
_EVENT_FIELDS = _EVENT_FIELDS
FORM_DATA = FORM_DATA
upload_files = upload_files
stop_propagation = stop_propagation
prevent_default = prevent_default
Expand Down Expand Up @@ -2396,6 +2418,8 @@ def wrapper(
key_event = staticmethod(key_event)
pointer_event_spec = staticmethod(pointer_event_spec)
no_args_event_spec = staticmethod(no_args_event_spec)
on_submit_event = staticmethod(on_submit_event)
on_submit_string_event = staticmethod(on_submit_string_event)

# Server Side Events
server_side = staticmethod(server_side)
Expand Down