|
17 | 17 | set_value_prop_on_select_element,
|
18 | 18 | transform_value_prop_on_input_element,
|
19 | 19 | )
|
20 |
| -from reactpy_django.forms.utils import convert_form_fields |
| 20 | +from reactpy_django.forms.utils import convert_form_fields, validate_form_args |
21 | 21 | from reactpy_django.types import AsyncFormEvent, FormEventData, SyncFormEvent
|
22 | 22 | from reactpy_django.utils import ensure_async
|
23 | 23 |
|
@@ -56,18 +56,8 @@ def _django_form(
|
56 | 56 | rendered_form, set_rendered_form = hooks.use_state(cast(Union[str, None], None))
|
57 | 57 | uuid = uuid_ref.current
|
58 | 58 |
|
59 |
| - # Validate the provided arguments |
60 |
| - if len(top_children) != top_children_count.current or len(bottom_children) != bottom_children_count.current: |
61 |
| - msg = "Dynamically changing the number of top or bottom children is not allowed." |
62 |
| - raise ValueError(msg) |
63 |
| - if not isinstance(form, (type(Form), type(ModelForm))): |
64 |
| - msg = ( |
65 |
| - "The provided form must be an uninitialized Django Form. " |
66 |
| - "Do NOT initialize your form by calling it (ex. `MyForm()`)." |
67 |
| - ) |
68 |
| - raise TypeError(msg) |
69 |
| - |
70 | 59 | # Initialize the form with the provided data
|
| 60 | + validate_form_args(top_children, top_children_count, bottom_children, bottom_children_count, form) |
71 | 61 | initialized_form = form(data=submitted_data)
|
72 | 62 | form_event = FormEventData(
|
73 | 63 | form=initialized_form, submitted_data=submitted_data or {}, set_submitted_data=set_submitted_data
|
|
0 commit comments