Feat v0.9.5 typed forms sdk (#79)
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m44s
CI/CD / test-sqlite (push) Successful in 3m6s
CI/CD / build-and-deploy (push) Successful in 29s
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m44s
CI/CD / test-sqlite (push) Successful in 3m6s
CI/CD / build-and-deploy (push) Successful in 29s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit was merged in pull request #79.
This commit is contained in:
@@ -429,3 +429,30 @@ def on_run(ctx):
|
||||
|
||||
return {"advance": True, "data": {"needs_review": False}}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## `forms` Module (v0.9.5)
|
||||
|
||||
**Permission:** `forms.validate`
|
||||
|
||||
Validates form data against a typed form template.
|
||||
|
||||
### `forms.validate(template, data)`
|
||||
|
||||
Validates `data` (a dict) against a `template` (a dict matching the TypedFormTemplate schema).
|
||||
|
||||
Returns a dict: `{"valid": True/False, "errors": [{"key": "...", "message": "..."}]}`.
|
||||
|
||||
```python
|
||||
result = forms.validate(
|
||||
{"fields": [{"key": "name", "type": "text", "label": "Name", "required": True}]},
|
||||
{"name": "Alice"},
|
||||
)
|
||||
# result["valid"] == True
|
||||
# result["errors"] == []
|
||||
```
|
||||
|
||||
Field types: `text`, `email`, `select`, `number`, `date`, `textarea`, `checkbox`, `file`.
|
||||
|
||||
Supports: required checks, min/max length, pattern (regex), number range, date range, select option whitelist, conditional visibility (`condition.when`/`op`/`value`).
|
||||
|
||||
Reference in New Issue
Block a user