- Docs
Forms documentation
Guides and reference for @samline/forms: validation, reactive state, serialization and auto-submit for native HTML forms.
@samline/forms binds a controller to a native HTMLFormElement. The controller reads values straight from the DOM, runs your validation rules, marks fields with attributes you can style, reports one state snapshot to subscribers and hands your submit handler a serialized object and a real FormData. It has no runtime dependencies and no framework adapter: the same API works in plain pages, server-rendered templates and component frameworks.
What it covers
- Validation — required, length, pattern and numeric rules, matching fields (
sameAs), declared dependencies (dependsOn), per-row rules (each) and custom validators that read every value. - State —
subscribe()for the whole form,observe()andwatch()for one field, plusgetState()andgetValue()for reads. - Submission —
onSubmit()handlers with promise tracking,autoSubmit()with debounce, server errors throughsetErrors(), andprefill()from the URL. - Formatting —
format(),formatAll()and theformatsoption, powered by the optional peer@samline/formatter. - Three ways to load it — ESM and CommonJS from npm, the
/browserregistry subpath, or a standalone script that defineswindow.Forms.
Choose your next step
Install the package, keep your markup and create your first controller.
Working examplesTwelve live forms with their code: validation, steps, conditional rules, formatting, auto-submit, server errors and more.
API referenceEvery controller method, registry helper and pure utility, grouped by task.
ChangelogRelease notes, including behavior changes and how to upgrade.