You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/reference/components.md
+101-4
Original file line number
Diff line number
Diff line change
@@ -156,7 +156,7 @@ Compatible with sync or async [Function Based Views](https://docs.djangoproject.
156
156
157
157
??? info "Existing limitations"
158
158
159
-
There are currently several limitations of using `#!python view_to_component` that may be resolved in a future version.
159
+
There are currently several limitations of using `#!python view_to_component` that will be [resolved in a future version](https://github.com/reactive-python/reactpy-django/issues/269).
160
160
161
161
- Requires manual intervention to change HTTP methods to anything other than `GET`.
162
162
- ReactPy events cannot conveniently be attached to converted view HTML.
@@ -292,12 +292,12 @@ Compatible with sync or async [Function Based Views](https://docs.djangoproject.
292
292
293
293
??? info "Existing limitations"
294
294
295
-
There are currently several limitations of using `#!python view_to_iframe` that may be resolved in a future version.
295
+
There are currently several limitations of using `#!python view_to_iframe` which may be [resolved in a future version](https://github.com/reactive-python/reactpy-django/issues/268).
296
296
297
297
- No built-in method of signalling events back to the parent component.
298
-
- All provided `#!python *args` and `#!python *kwargs` must be serializable values, since they are encoded into the URL.
298
+
- All provided `#!python args` and `#!python kwargs` must be serializable values, since they are encoded into the URL.
299
299
- The `#!python iframe` will always load **after** the parent component.
300
-
- CSS styling for `#!python iframe` elements tends to be awkward/difficult.
300
+
- CSS styling for `#!python iframe` elements tends to be awkward.
301
301
302
302
??? question "How do I use this for Class Based Views?"
303
303
@@ -381,6 +381,103 @@ Compatible with sync or async [Function Based Views](https://docs.djangoproject.
381
381
382
382
---
383
383
384
+
## Django Form
385
+
386
+
Automatically convert a Django form into a ReactPy component.
387
+
388
+
Compatible with both [standard Django forms](https://docs.djangoproject.com/en/stable/topics/forms/#building-a-form) and [ModelForms](https://docs.djangoproject.com/en/stable/topics/forms/modelforms/).
389
+
390
+
=== "components.py"
391
+
392
+
```python
393
+
{% include "../../examples/python/django_form.py" %}
394
+
```
395
+
396
+
=== "forms.py"
397
+
398
+
```python
399
+
{% include "../../examples/python/django_form_class.py" %}
400
+
```
401
+
402
+
??? example "See Interface"
403
+
404
+
<font size="4">**Parameters**</font>
405
+
406
+
| Name | Type | Description | Default |
407
+
| --- | --- | --- | --- |
408
+
| `#!python form` | `#!python type[Form | ModelForm]` | The form instance to convert. | N/A |
409
+
| `#!python on_success` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called when the form is successfully submitted. | `#!python None` |
410
+
| `#!python on_error` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called when the form submission fails. | `#!python None` |
411
+
| `#!python on_receive_data` | `#!python AsyncFormEvent | SyncFormEvent | None` | A callback function that is called before newly submitted form data is rendered. | `#!python None` |
412
+
| `#!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` |
414
+
| `#!python extra_props` | `#!python dict[str, Any] | None` | Additional properties to add to the `#!html <form>` element. | `#!python None` |
415
+
| `#!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` |
416
+
| `#!python form_template` | `#!python str | None` | The template to use for the form. If `#!python None`, Django's default template is used. | `#!python None` |
417
+
| `#!python top_children` | `#!python Sequence[Any]` | Additional elements to add to the top of the form. | `#!python tuple` |
418
+
| `#!python bottom_children` | `#!python Sequence[Any]` | Additional elements to add to the bottom of the form. | `#!python tuple` |
419
+
| `#!python key` | `#!python Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings. | `#!python None` |
420
+
421
+
<font size="4">**Returns**</font>
422
+
423
+
| Type | Description |
424
+
| --- | --- |
425
+
| `#!python Component` | A ReactPy component. |
426
+
427
+
??? info "Existing limitations"
428
+
429
+
The following fields are currently incompatible with `#!python django_form`: `#!python FileField`, `#!python ImageField`, `#!python SplitDateTimeField`, and `#!python MultiValueField`.
430
+
431
+
Compatibility for these fields will be [added in a future version](https://github.com/reactive-python/reactpy-django/issues/270).
432
+
433
+
??? question "How do I style these forms with Bootstrap?"
434
+
435
+
You can style these forms by using a form styling library. In the example below, it is assumed that you have already installed [`django-bootstrap5`](https://pypi.org/project/django-bootstrap5/).
436
+
437
+
After installing a form styling library, you can then provide ReactPy a custom `#!python form_template` parameter. This parameter allows you to specify a custom HTML template to use to render this the form.
438
+
439
+
Note that you can also set a global default for `form_template` by using [`settings.py:REACTPY_DEFAULT_FORM_TEMPLATE`](./settings.md#reactpy_default_form_template).
440
+
441
+
=== "components.py"
442
+
443
+
```python
444
+
{% include "../../examples/python/django_form_bootstrap.py" %}
445
+
```
446
+
447
+
=== "forms.py"
448
+
449
+
```python
450
+
{% include "../../examples/python/django_form_class.py" %}
451
+
```
452
+
453
+
=== "bootstrap_form.html"
454
+
455
+
```jinja
456
+
{% include "../../examples/html/django_form_bootstrap.html" %}
457
+
```
458
+
459
+
??? question "How do I handle form success/errors?"
460
+
461
+
You can react to form state by providing a callback function to any of the following parameters: `#!python on_success`, `#!python on_error`, `#!python on_receive_data`, and `#!python on_change`.
462
+
463
+
These functions will be called when the form is submitted.
464
+
465
+
In the example below, we will use the `#!python on_success` parameter to change the URL upon successful submission.
466
+
467
+
=== "components.py"
468
+
469
+
```python
470
+
{% include "../../examples/python/django_form_on_success.py" %}
471
+
```
472
+
473
+
=== "forms.py"
474
+
475
+
```python
476
+
{% include "../../examples/python/django_form_class.py" %}
477
+
```
478
+
479
+
---
480
+
384
481
## Django CSS
385
482
386
483
Allows you to defer loading a CSS stylesheet until a component begins rendering. This stylesheet must be stored within [Django's static files](https://docs.djangoproject.com/en/stable/howto/static-files/).
@@ -131,7 +143,7 @@ This setting is incompatible with [`daphne`](https://github.com/django/daphne).
131
143
132
144
Configures whether to use an async ReactPy rendering queue. When enabled, large renders will no longer block smaller renders from taking place. Additionally, prevents the rendering queue from being blocked on waiting for async effects to startup/shutdown (which is typically a relatively slow operation).
133
145
134
-
This setting is currently experimental, and currently no effort is made to de-duplicate renders. For example, if parent and child components are scheduled to render at the same time, both renders will take place even though a single render of the parent component would have been sufficient.
146
+
This setting is currently in early release, and currently no effort is made to de-duplicate renders. For example, if parent and child components are scheduled to render at the same time, both renders will take place even though a single render of the parent component would have been sufficient.
0 commit comments