1313from reactpy_django .forms .transforms import (
1414 convert_html_props_to_reactjs ,
1515 convert_textarea_children_to_prop ,
16+ infer_key_from_attributes ,
1617 intercept_anchor_links ,
1718 set_value_prop_on_select_element ,
1819 transform_value_prop_on_input_element ,
@@ -56,7 +57,7 @@ def _django_form(
5657 rendered_form , set_rendered_form = hooks .use_state (cast (Union [str , None ], None ))
5758 uuid = uuid_ref .current
5859
59- # Check the provided arguments
60+ # Validate the provided arguments
6061 if len (top_children ) != top_children_count .current or len (bottom_children ) != bottom_children_count .current :
6162 msg = "Dynamically changing the number of top or bottom children is not allowed."
6263 raise ValueError (msg )
@@ -67,14 +68,14 @@ def _django_form(
6768 )
6869 raise TypeError (msg )
6970
70- # Try to initialize the form with the provided data
71+ # Initialize the form with the provided data
7172 initialized_form = form (data = submitted_data )
7273 form_event = FormEventData (
7374 form = initialized_form , submitted_data = submitted_data or {}, set_submitted_data = set_submitted_data
7475 )
7576
7677 # Validate and render the form
77- @hooks .use_effect
78+ @hooks .use_effect ( dependencies = [ str ( submitted_data )])
7879 async def render_form ():
7980 """Forms must be rendered in an async loop to allow database fields to execute."""
8081 if submitted_data :
@@ -85,14 +86,12 @@ async def render_form():
8586 if not success and on_error :
8687 await ensure_async (on_error , thread_sensitive = thread_sensitive )(form_event )
8788 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 )()
8990 set_submitted_data (None )
9091
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 )
9394 )
94- if new_form != rendered_form :
95- set_rendered_form (new_form )
9695
9796 async def on_submit_callback (new_data : dict [str , Any ]):
9897 """Callback function provided directly to the client side listener. This is responsible for transmitting
@@ -134,6 +133,7 @@ async def _on_change(_event):
134133 set_value_prop_on_select_element ,
135134 transform_value_prop_on_input_element ,
136135 intercept_anchor_links ,
136+ infer_key_from_attributes ,
137137 * extra_transforms ,
138138 strict = False ,
139139 ),
0 commit comments