Skip to content

Commit d561c88

Browse files
committed
self review
1 parent 16c04bc commit d561c88

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

docs/examples/python/django_form_on_success.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88

99
@component
1010
def basic_form():
11-
success, set_success = hooks.use_state(False)
11+
submitted, set_submitted = hooks.use_state(False)
1212

13-
def on_success(event: FormEventData):
14-
set_success(True)
13+
def on_submit(event: FormEventData):
14+
"""This function will be called when the form is successfully submitted."""
15+
set_submitted(True)
1516

16-
if not success:
17-
children = [html.input({"type": "submit"})]
18-
return django_form(MyForm, on_success=on_success, bottom_children=children)
17+
if submitted:
18+
return navigate("/homepage")
1919

20-
return navigate("/homepage")
20+
children = [html.input({"type": "submit"})]
21+
return django_form(MyForm, on_success=on_submit, bottom_children=children)

docs/src/reference/components.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -405,12 +405,12 @@ Compatible with both [standard Django forms](https://docs.djangoproject.com/en/s
405405

406406
| Name | Type | Description | Default |
407407
| --- | --- | --- | --- |
408-
| `#!python form` | `#!python type[Form | ModelForm]` | The form instance to convert. | N/A |
408+
| `#!python form` | `#!python type[Form | ModelForm]` | The form to convert. | N/A |
409409
| `#!python on_success` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called when the form is successfully submitted. | `#!python None` |
410410
| `#!python on_error` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called when the form submission fails. | `#!python None` |
411411
| `#!python on_receive_data` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called before newly submitted form data is rendered. | `#!python None` |
412412
| `#!python on_change` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called when the form is changed. | `#!python None` |
413-
| `#!python auto_save` | `#!python bool` | If `#!python True`, the form will automatically call `#!python save` on successful submission of a `#!python ModelForm`. This has no effect on regular `#!python Form` instances. | `#!python False` |
413+
| `#!python auto_save` | `#!python bool` | If `#!python True`, the form will automatically call `#!python save` on successful submission of a `#!python ModelForm`. This has no effect on regular `#!python Form` instances. | `#!python True` |
414414
| `#!python extra_props` | `#!python dict[str, Any] | None` | Additional properties to add to the `#!html <form>` element. | `#!python None` |
415415
| `#!python extra_transforms` | `#!python Sequence[Callable[[VdomDict], Any]] | None` | A list of functions that transforms the newly generated VDOM. The functions will be repeatedly called on each VDOM node. | `#!python None` |
416416
| `#!python form_template` | `#!python str | None` | The template to use for the form. If `#!python None`, Django's default template is used. | `#!python None` |

src/reactpy_django/components.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""This file contains Django related components. Most of these components utilize wrappers to fix type hints."""
2+
13
from __future__ import annotations
24

35
import json
@@ -136,7 +138,7 @@ def django_form(
136138
"""Converts a Django form to a ReactPy component.
137139
138140
Args:
139-
form: The form instance to convert.
141+
form: The form to convert.
140142
141143
Keyword Args:
142144
on_success: A callback function that is called when the form is successfully submitted.

0 commit comments

Comments
 (0)