Form Array
Style-agnostic form array component.
Preview
Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import FormArray
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = FormArray()
@event_handler()
def add_row(self, **kwargs):
self.component.rows = ... # `append_row` — see this component's docs
@event_handler()
def remove_row(self, **kwargs):
... # write to self.component; the re-render carries itmy_template.html
django
{{ component }}Events this component sends to the view: add_row, remove_row.
Parameters
| Name | Type | Default |
|---|---|---|
| name | str | 'items' |
| rows | list | None | None |
| min | int | 1 |
| max | int | 10 |
| add_event | str — renames the event | 'add_row' |
| remove_event | str — renames the event | 'remove_row' |
| add_label | str | 'Add row' |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.form_array | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 5 of this component's classes at line 1831, 1832, 1833, 1834, 1836. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |