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
+102-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,104 @@ 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 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 a form field is modified by the user. | `#!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 True` |
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 thread_sensitive` | `#!python bool` | Whether to run event callback functions in thread sensitive mode. This mode only applies to sync functions, and is turned on by default due to Django ORM limitations. | `#!python True` |
418
+
| `#!python top_children` | `#!python Sequence[Any]` | Additional elements to add to the top of the form. | `#!python tuple` |
419
+
| `#!python bottom_children` | `#!python Sequence[Any]` | Additional elements to add to the bottom of the form. | `#!python tuple` |
420
+
| `#!python key` | `#!python Key | None` | A key to uniquely identify this component which is unique amongst a component's immediate siblings. | `#!python None` |
421
+
422
+
<font size="4">**Returns**</font>
423
+
424
+
| Type | Description |
425
+
| --- | --- |
426
+
| `#!python Component` | A ReactPy component. |
427
+
428
+
??? info "Existing limitations"
429
+
430
+
The following fields are currently incompatible with `#!python django_form`: `#!python FileField`, `#!python ImageField`, `#!python SplitDateTimeField`, and `#!python MultiValueField`.
431
+
432
+
Compatibility for these fields will be [added in a future version](https://github.com/reactive-python/reactpy-django/issues/270).
433
+
434
+
??? question "How do I style these forms with Bootstrap?"
435
+
436
+
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/).
437
+
438
+
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.
439
+
440
+
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).
441
+
442
+
=== "components.py"
443
+
444
+
```python
445
+
{% include "../../examples/python/django_form_bootstrap.py" %}
446
+
```
447
+
448
+
=== "forms.py"
449
+
450
+
```python
451
+
{% include "../../examples/python/django_form_class.py" %}
452
+
```
453
+
454
+
=== "bootstrap_form.html"
455
+
456
+
```jinja
457
+
{% include "../../examples/html/django_form_bootstrap.html" %}
458
+
```
459
+
460
+
??? question "How do I handle form success/errors?"
461
+
462
+
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`.
463
+
464
+
These functions will be called when the form is submitted.
465
+
466
+
In the example below, we will use the `#!python on_success` parameter to change the URL upon successful submission.
467
+
468
+
=== "components.py"
469
+
470
+
```python
471
+
{% include "../../examples/python/django_form_on_success.py" %}
472
+
```
473
+
474
+
=== "forms.py"
475
+
476
+
```python
477
+
{% include "../../examples/python/django_form_class.py" %}
478
+
```
479
+
480
+
---
481
+
384
482
## Django CSS
385
483
386
484
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/).
Copy file name to clipboardexpand all lines: docs/src/reference/hooks.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ Query functions can be sync or async.
46
46
| --- | --- | --- | --- |
47
47
| `#!python query` | `#!python Callable[FuncParams, Awaitable[Inferred]] | Callable[FuncParams, Inferred]` | A function that executes a query and returns some data. | N/A |
48
48
| `#!python kwargs` | `#!python dict[str, Any] | None` | Keyword arguments to passed into the `#!python query` function. | `#!python None` |
49
-
| `#!python thread_sensitive` | `#!python bool` | Whether to run your query function in thread sensitive mode. This mode only applies to sync query functions, and is turned on by default due to Django ORM limitations. | `#!python True` |
49
+
| `#!python thread_sensitive` | `#!python bool` | Whether to run your query function in thread sensitive mode. This setting only applies to sync functions, and is turned on by default due to Django ORM limitations. | `#!python True` |
50
50
| `#!python postprocessor` | `#!python AsyncPostprocessor | SyncPostprocessor | None` | A callable that processes the query `#!python data` before it is returned. The first argument of postprocessor function must be the query `#!python data`. All proceeding arguments are optional `#!python postprocessor_kwargs`. This postprocessor function must return the modified `#!python data`. | `#!python None` |
@@ -188,7 +188,7 @@ Mutation functions can be sync or async.
188
188
| Name | Type | Description | Default |
189
189
| --- | --- | --- | --- |
190
190
| `#!python mutation` | `#!python Callable[FuncParams, bool | None] | Callable[FuncParams, Awaitable[bool | None]]` | A callable that performs Django ORM create, update, or delete functionality. If this function returns `#!python False`, then your `#!python refetch` function will not be used. | N/A |
191
-
| `#!python thread_sensitive` | `#!python bool` | Whether to run the mutation in thread sensitive mode. This mode only applies to sync mutation functions, and is turned on by default due to Django ORM limitations. | `#!python True` |
191
+
| `#!python thread_sensitive` | `#!python bool` | Whether to run the mutation in thread sensitive mode. This setting only applies to sync functions, and is turned on by default due to Django ORM limitations. | `#!python True` |
192
192
| `#!python refetch` | `#!python Callable[..., Any] | Sequence[Callable[..., Any]] | None` | A query function (the function you provide to your `#!python use_query` hook) or a sequence of query functions that need a `#!python refetch` if the mutation succeeds. This is useful for refreshing data after a mutation has been performed. | `#!python None` |
@@ -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