WardrikWeb. Form
(wardrik_web v0.1.0-rc.1)
Copy Markdown
Builds a form from a JSON Schema, and reads the submitted form back into a value.
| Schema | Form |
|---|---|
| string, number, boolean, enum | a field |
| object | a fieldset |
| array of objects | a group you can repeat |
oneOf | a choice between the alternatives |
string with "writeOnly": true | a password field |
<WardrikWeb.Form.fields schema={schema} params={@params} />
{:ok, input} = WardrikWeb.Form.read(schema, params["input"])- Fields are named
input[...]. The submitted params hold them under"input". params/2fills the form with an existing value, for example a saved definition.- If the form has repeatable groups, handle the
"form-add"and"form-remove"events withhandle/3. Update@paramsonphx-change. read/2leaves out empty fields.
Summary
Functions
Adds an empty group to the array of objects at path in params.
Renders the fields for an object schema, filled with params.
Handles the "form-add" and "form-remove" events. Returns the updated params.
Returns the kind of field for schema. Long text fields, like instructions, get a text area.
Returns the params that fill a form for schema with value.
Reads submitted params as a value of schema. Empty fields are left out. Returns :none if every field is empty.
Removes the group at path in params.
Types
Functions
Adds an empty group to the array of objects at path in params.
Renders the fields for an object schema, filled with params.
Use :only or :except to choose which top-level properties to show. Required fields come
first.
Attributes
schema(:map) (required)params(:any) - Defaults to%{}.only(:list) - Defaults tonil.except(:list) - Defaults to[].target(:any) - Thephx-targetof the add and remove buttons. Defaults tonil.
Handles the "form-add" and "form-remove" events. Returns the updated params.
Returns nil for any other event.
Returns the kind of field for schema. Long text fields, like instructions, get a text area.
Returns the params that fill a form for schema with value.
Reads submitted params as a value of schema. Empty fields are left out. Returns :none if every field is empty.
Removes the group at path in params.