rg.forms¶
Reactive Django Forms with Datastar integration.
rg.forms lets you build dynamic Django forms where fields react to each other — visibility, requirements, computed values, and cascading dropdowns — all declared in Python.
Features¶
visible_when— show/hide fields based on other field valuesrequired_when— make fields conditionally requiredcomputed— automatic calculations from other fieldsdisabled_when/read_only_when— conditional field stateschoices_from+depends_on— declarative cascading dropdowns- Field groups — organize fields into sections with shared visibility
- Backend validation — hidden fields are skipped, dynamic requirements enforced
- Datastar-powered — reactive UI with minimal JavaScript
How it works¶
- You define reactive rules in Python on your form fields
- rg.forms generates Datastar attributes (
data-show,data-bind,data-computed, etc.) - The frontend reacts instantly — no page reloads
- On submit, the backend re-evaluates all rules for security
from rg.forms import ReactiveForm, ReactiveChoiceField, ReactiveCharField
class OrderForm(ReactiveForm):
order_type = ReactiveChoiceField(choices=[
('standard', 'Standard'),
('urgent', 'Urgent'),
])
priority = ReactiveChoiceField(
choices=[('low', 'Low'), ('high', 'High')],
visible_when="$order_type == 'urgent'",
)
The priority field only appears when the user selects "Urgent". On form submission, if order_type is not "urgent", the priority field is skipped during validation.
Installation¶
Add to your Django settings:
Requirements¶
- Python 3.12+
- Django 5.0+
- Datastar loaded on the frontend
Next steps¶
- Quick Start — build your first reactive form
- Guide — learn all reactive features
- Reference — full API reference