13
13
from reactpy_django .forms .transforms import (
14
14
convert_html_props_to_reactjs ,
15
15
convert_textarea_children_to_prop ,
16
+ infer_key_from_attributes ,
16
17
intercept_anchor_links ,
17
18
set_value_prop_on_select_element ,
18
19
transform_value_prop_on_input_element ,
@@ -56,7 +57,7 @@ def _django_form(
56
57
rendered_form , set_rendered_form = hooks .use_state (cast (Union [str , None ], None ))
57
58
uuid = uuid_ref .current
58
59
59
- # Check the provided arguments
60
+ # Validate the provided arguments
60
61
if len (top_children ) != top_children_count .current or len (bottom_children ) != bottom_children_count .current :
61
62
msg = "Dynamically changing the number of top or bottom children is not allowed."
62
63
raise ValueError (msg )
@@ -67,14 +68,14 @@ def _django_form(
67
68
)
68
69
raise TypeError (msg )
69
70
70
- # Try to initialize the form with the provided data
71
+ # Initialize the form with the provided data
71
72
initialized_form = form (data = submitted_data )
72
73
form_event = FormEventData (
73
74
form = initialized_form , submitted_data = submitted_data or {}, set_submitted_data = set_submitted_data
74
75
)
75
76
76
77
# Validate and render the form
77
- @hooks .use_effect
78
+ @hooks .use_effect ( dependencies = [ str ( submitted_data )])
78
79
async def render_form ():
79
80
"""Forms must be rendered in an async loop to allow database fields to execute."""
80
81
if submitted_data :
@@ -85,14 +86,12 @@ async def render_form():
85
86
if not success and on_error :
86
87
await ensure_async (on_error , thread_sensitive = thread_sensitive )(form_event )
87
88
if success and auto_save and isinstance (initialized_form , ModelForm ):
88
- await database_sync_to_async (initialized_form .save )()
89
+ await ensure_async (initialized_form .save )()
89
90
set_submitted_data (None )
90
91
91
- new_form = await database_sync_to_async ( initialized_form . render ) (
92
- form_template or config .REACTPY_DEFAULT_FORM_TEMPLATE
92
+ set_rendered_form (
93
+ await ensure_async ( initialized_form . render )( form_template or config .REACTPY_DEFAULT_FORM_TEMPLATE )
93
94
)
94
- if new_form != rendered_form :
95
- set_rendered_form (new_form )
96
95
97
96
async def on_submit_callback (new_data : dict [str , Any ]):
98
97
"""Callback function provided directly to the client side listener. This is responsible for transmitting
@@ -134,6 +133,7 @@ async def _on_change(_event):
134
133
set_value_prop_on_select_element ,
135
134
transform_value_prop_on_input_element ,
136
135
intercept_anchor_links ,
136
+ infer_key_from_attributes ,
137
137
* extra_transforms ,
138
138
strict = False ,
139
139
),
0 commit comments