mirror of
https://github.com/hanzoai/form.js.git
synced 2026-09-30 21:50:42 +00:00
81c99e4e474b8fd78e6519954c7ba649e4c8c770
github.com has no runner for hanzo-build-linux-amd64, so a caller under .github/workflows is a gate that can never be scheduled. This is the ~7-line caller on the plane that can (git.hanzo.ai git-runner fleet), pinned @v1. Co-authored-by: Hanzo Dev <[email protected]>
Form.js
Automagic form validation and submission.
Install
npm install form.js
Or drop it inside a <form> and let it wire itself to the surrounding fields:
<form>
<script src="https://unpkg.com/form.js" data-key="pk_live_β¦"></script>
<input name="email">
<button type="submit">Sign up</button>
</form>
Submission
Without a key, form.js is a thin controller around the surrounding form: it emits lifecycle events and hands control back to your page. Set a Hanzo publishable key on the script tag and it POSTs the serialized form to the Hanzo forms ingest instead:
POST https://api.hanzo.ai/v1/forms
Authorization: Bearer pk_live_β¦
Content-Type: application/json
{ "email": "[email protected]", "metadata": { "name": "Ada" } }
Script-tag options (all data-*):
| attribute | purpose |
|---|---|
data-key |
publishable key (pk_live_β¦ / pk_test_β¦) |
data-token |
@hanzo/iam access token (takes precedence over key) |
data-endpoint |
override the full submission URL |
data-host |
override the API host (default https://api.hanzo.ai) |
Events
window.Inform is an event emitter β listen with Inform.on / Inform.once:
| event | Inform.Events |
arguments |
|---|---|---|
init-inform-script |
InitScript |
the <script> element |
init-inform-form |
InitForm |
the <form> element |
init-inform-inputs |
InitInputs |
array of input/select nodes |
init-inform-submits |
InitSubmits |
array of submit buttons |
inform-submit |
OnSubmit |
unmanaged: (done, event); managed: (payload, event) |
inform-done |
OnDone |
the submit event, or the API response (managed) |
inform-error |
OnError |
submission error (managed) |
In unmanaged mode, call done() from your OnSubmit listener to let the native
form submit proceed.
License
Languages
CoffeeScript
55.1%
JavaScript
35.7%
HTML
9.2%