Form Array

Style-agnostic form array component.

python 9 params

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 it
my_template.html
django
{{ component }}

Events this component sends to the view: add_row, remove_row.

Parameters

NameTypeDefault
namestr'items'
rowslist | NoneNone
minint1
maxint10
add_eventstr — renames the event'add_row'
remove_eventstr — renames the event'remove_row'
add_labelstr'Add row'
custom_classstr''
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.form_arraySubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.