Form uploads, submit and presentation DSL
v0.0.1
The uploads, submit and presentation sections of a resource's form block configure file uploads, the submit and cancel buttons, and the template, UI adapter and theme of the form.
uploads.upload
Declares a file upload. Pair it with a field of type :upload of the same name. It sits at mishka_gervaz.form.uploads.upload.
Call: upload name
Arguments:
| Argument | Type | Default | Description |
|---|---|---|---|
name | atom | none | Required. The upload name. Gervaz joins it with the component id to make the key of allow_upload. |
Options:
| Option | Type | Default | Description |
|---|---|---|---|
field | atom | none | Form field this upload is associated with. |
accept | String.t | list(String.t) | none | Accepted file types: a string such as "image/*,.pdf" or a list such as ~w(.jpg .png .pdf). Set it: LiveView raises for an upload that has no accept. |
max_entries | pos_integer | 1 | Maximum number of files. |
max_file_size | pos_integer | 8000000 | Maximum file size in bytes. |
show_preview | boolean | true | Shows a file preview. The value is compiled into the config, but no built-in template or handler reads it. |
dropzone_text | String.t | (-> any) | none | Text for the dropzone. The value is compiled into the config, but no built-in template or handler reads it. |
auto_upload | boolean | false | Auto-upload on file selection. |
style | :dropzone | :file_input | :custom | :dropzone | :dropzone (the default) is a drag-and-drop zone. :file_input is the standard file picker. :custom is a bare live_file_input. |
chunk_size | pos_integer | none | Bytes per chunk for chunked uploads. |
chunk_timeout | pos_integer | none | Chunk timeout in milliseconds. |
external | (any, any -> any) | atom | none | A function fn entry, socket -> ... for direct uploads, for example to S3. LiveView accepts only a function here, so a module name fails when the form mounts. |
writer | atom | none | A module, as the DSL types it. LiveView expects a function of three arguments for this option, so treat it as not working. |
existing | atom | (any -> any) | none | How to read already uploaded files off the record in edit mode: a field name, or fn record -> list. |
upload ui
How the upload is drawn. It sits at mishka_gervaz.form.uploads.upload.ui.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Upload label. The value is compiled into the config, but no built-in template or handler reads it. |
icon | String.t | none | Upload icon. The value is compiled into the config, but no built-in template or handler reads it. |
class | String.t | none | Upload CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
preview_class | String.t | none | Preview area CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
extra | map | %{} | Additional options. The value is compiled into the config, but no built-in template or handler reads it. |
submit
The submit row. It is an entity with three button entities and a shared ui block. It sits at mishka_gervaz.form.submit.
| Option | Type | Default | Description |
|---|---|---|---|
position | :top | :bottom | :both | :bottom | Button position. The value is compiled into the config, but no built-in template or handler reads it. |
create
The create button. It sits at mishka_gervaz.form.submit.create.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Button label. String or zero-arity function. |
active | boolean | (any -> any) | true | Whether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only. |
disabled | boolean | (any -> any) | false | Disable button. Boolean or fn state -> boolean end. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. fn state -> boolean() end. |
restricted | boolean | (any -> any) | false | Restrict to master users. true or fn state -> boolean() end. |
update
The update button. It sits at mishka_gervaz.form.submit.update.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Button label. String or zero-arity function. |
active | boolean | (any -> any) | true | Whether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only. |
disabled | boolean | (any -> any) | false | Disable button. Boolean or fn state -> boolean end. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. fn state -> boolean() end. |
restricted | boolean | (any -> any) | false | Restrict to master users. true or fn state -> boolean() end. |
cancel
The cancel button. It sits at mishka_gervaz.form.submit.cancel.
| Option | Type | Default | Description |
|---|---|---|---|
label | String.t | (-> any) | none | Button label. String or zero-arity function. |
active | boolean | (any -> any) | true | Whether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only. |
disabled | boolean | (any -> any) | false | Disable button. Boolean or fn state -> boolean end. |
visible | boolean | (any -> any) | true | Static or dynamic visibility. fn state -> boolean() end. |
restricted | boolean | (any -> any) | false | Restrict to master users. true or fn state -> boolean() end. |
submit ui
Classes for the submit row. It sits at mishka_gervaz.form.submit.ui.
| Option | Type | Default | Description |
|---|---|---|---|
submit_class | String.t | none | Submit button CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
cancel_class | String.t | none | Cancel button CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
wrapper_class | String.t | none | Button wrapper CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
extra | map | %{} | Additional options. The value is compiled into the config, but no built-in template or handler reads it. |
presentation
Picks the template, the UI adapter, the features and the debounce. It sits at mishka_gervaz.form.presentation.
| Option | Type | Default | Description |
|---|---|---|---|
debounce | integer | none | Default debounce milliseconds for all fields. Overridden per-field via ui do debounce end. |
template | atom | MishkaGervaz.Form.Templates.Standard | The form template module. Built in: MishkaGervaz.Form.Templates.Standard, which draws all three layout modes. |
ui_adapter | atom | MishkaGervaz.UIAdapters.Tailwind | The UI adapter module that draws inputs, groups and buttons. One adapter serves both tables and forms. |
ui_adapter_opts | keyword | [] | Options for the adapter. Gervaz stores it. The form does not read it, and it does not generate an adapter from it. |
features | :all | list(:validation | :uploads | :groups | :wizard | :autosave | :inline_errors) | :all | The features to enable. Accepted: :validation, :uploads, :groups, :wizard, :autosave and :inline_errors. The built-in template does not check it. A custom template can honor it. |
theme
Theme classes. It sits at mishka_gervaz.form.presentation.theme.
| Option | Type | Default | Description |
|---|---|---|---|
form_class | String.t | none | Form element CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
field_class | String.t | none | Default field CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
label_class | String.t | none | Default label CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
error_class | String.t | none | Error message CSS classes. The value is compiled into the config, but no built-in template or handler reads it. |
extra | map | %{} | Template-specific theming options. The value is compiled into the config, but no built-in template or handler reads it. |