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: README.md
+153Lines changed: 153 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -246,6 +246,159 @@ print(result["errors"][0]["message"]) # "El campo name es requerido"
246
246
247
247
See [`examples/i18n_usage.py`](examples/i18n_usage.py) for a full working example.
248
248
249
+
## Dynamic Forms
250
+
251
+
### Conditional Visibility
252
+
253
+
Fields can be shown or hidden based on the value of other fields using `visible_when`. This is metadata that your frontend can use for dynamic UI, and the backend can respect during validation.
254
+
255
+
```python
256
+
from codeforms import Form, TextField, SelectField, SelectOption, VisibilityRule
The `dependent_options` metadata serializes to JSON for your frontend to consume. See [`examples/dependent_options.py`](examples/dependent_options.py).
343
+
344
+
## Multi-Step Wizard Forms
345
+
346
+
Use `FormStep` to split a form into multiple steps. Each step contains its own fields and can be validated independently.
347
+
348
+
```python
349
+
from codeforms import Form, FormStep, TextField, EmailField, CheckboxField
CheckboxField(name="terms", label="I accept the terms", required=True),
366
+
],
367
+
validation_mode="on_submit",
368
+
),
369
+
],
370
+
)
371
+
```
372
+
373
+
### Step Validation
374
+
375
+
```python
376
+
# Validate a single step
377
+
result = form.validate_step(0, {"name": "John", "email": "john@example.com"})
378
+
print(result["success"]) # True
379
+
380
+
# Validate all steps at once
381
+
result = form.validate_all_steps({
382
+
"name": "John",
383
+
"email": "john@example.com",
384
+
"terms": True,
385
+
})
386
+
print(result["success"]) # True
387
+
```
388
+
389
+
### Wizard Helpers
390
+
391
+
```python
392
+
steps = form.get_steps() # List[FormStep]
393
+
fields = form.fields # Flat list of all fields across all steps
394
+
```
395
+
396
+
### HTML Export
397
+
398
+
Wizard forms export with `data-wizard="true"` on the `<form>` tag. Each step renders as a `<section data-step="true">` (not `<fieldset>`), so you can wire up your own step navigation in JavaScript.
399
+
400
+
See [`examples/wizard_form.py`](examples/wizard_form.py) for a full working example.
401
+
249
402
## Custom Field Types
250
403
251
404
You can create your own field types by subclassing `FormFieldBase` and registering them with `register_field_type()`. Custom fields integrate seamlessly with forms, JSON serialization, validation, and HTML export.
0 commit comments