Skip to content

Commit 24cc64b

Browse files
committed
Add on_change event
1 parent 4565df0 commit 24cc64b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/reactpy_django/components.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def django_form(
125125
on_success: Callable[[FormEvent], None] | None = None,
126126
on_error: Callable[[FormEvent], None] | None = None,
127127
on_submit: Callable[[FormEvent], None] | None = None,
128+
on_change: Callable[[FormEvent], None] | None = None,
128129
form_template: str | None = None,
129130
top_children: Sequence = (),
130131
bottom_children: Sequence = (),
@@ -136,6 +137,7 @@ def django_form(
136137
on_success=on_success,
137138
on_error=on_error,
138139
on_submit=on_submit,
140+
on_change=on_change,
139141
form_template=form_template,
140142
top_children=top_children,
141143
bottom_children=bottom_children,

src/reactpy_django/forms/components.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def _django_form(
3535
on_success: Callable[[FormEvent], None] | None,
3636
on_error: Callable[[FormEvent], None] | None,
3737
on_submit: Callable[[FormEvent], None] | None,
38+
on_change: Callable[[FormEvent], None] | None,
3839
form_template: str | None,
3940
top_children: Sequence,
4041
bottom_children: Sequence,
@@ -78,6 +79,10 @@ def _django_form(
7879
if not success and on_error:
7980
on_error(form_event)
8081

82+
def _on_change(_event):
83+
if on_change:
84+
on_change(FormEvent(form=initialized_form, data=submitted_data or {}))
85+
8186
def on_submit_callback(new_data: dict[str, Any]):
8287
"""Callback function provided directly to the client side listener. This is responsible for transmitting
8388
the submitted form data to the server for processing."""
@@ -91,7 +96,8 @@ def on_submit_callback(new_data: dict[str, Any]):
9196
set_submitted_data(new_data)
9297

9398
return html.form(
94-
{"id": f"reactpy-{uuid}", "onSubmit": event(lambda _: None, prevent_default=True)} | extra_props,
99+
{"id": f"reactpy-{uuid}", "onSubmit": event(lambda _: None, prevent_default=True), "onChange": _on_change}
100+
| extra_props,
95101
DjangoForm({"onSubmitCallback": on_submit_callback, "formId": f"reactpy-{uuid}"}),
96102
*top_children,
97103
utils.html_to_vdom(

0 commit comments

Comments
 (0)