Forms, uploads and loading feedback
A form with on-submit can send several bindings in one action. Paste this block into index.html, enter a name, and click Greet to see the result. The binding is sent when you submit the form.
<live id="greeting-form">
<state name="name" value="''" />
<state name="message" value="''" />
<form on-submit="$message = 'Hello, ' + $name + '!'">
<label>Name <input @bind($name, on: action) required></label>
<button live-disable>Greet</button>
</form>
<p role="status">{$message}</p>
</live>Use HTML controls such as required for immediate feedback and KScript types or rules for server validation. To save to a database, use model forms.
| Attribute | Browser behavior |
|---|---|
live-loading |
Shows the element while the action is pending. |
live-disable |
Disables the control until the request completes. |
live-dirty |
Shows the element when a bound value has unsent edits. Give it a binding name to watch one field. |
live-offline |
Shows the element while the browser reports that it is offline. |
live-error |
Shows feedback when the action fails. |
live-cloak |
Hides markup until the live runtime starts. |
Use live-upload on a named file input. The upload travels with its on-change action or its form's on-submit action. For an input named attachment, $event.files.attachment contains file entries with name, type, size and base64 bytes. The request accepts up to 8 MiB of files. Validate content and permissions before saving. Mark the file input live-replace to clear its selection on the next redraw.
Use @live_download('report.txt', bytes: $report->to_base64()) to offer bytes generated by an action as a file.