Form uploads, submit and presentation DSL

v0.0.12

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:

ArgumentTypeDefaultDescription
nameatomnoneRequired. The upload name. Gervaz joins it with the component id to make the key of allow_upload.

Options:

OptionTypeDefaultDescription
fieldatomnoneForm field this upload is associated with.
acceptString.t | list(String.t)noneAccepted 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_entriespos_integer1Maximum number of files.
max_file_sizepos_integer8000000Maximum file size in bytes.
show_previewbooleantrueShows a file preview. The value is compiled into the config, but no built-in template or handler reads it.
dropzone_textString.t | (-> any)noneText for the dropzone. The value is compiled into the config, but no built-in template or handler reads it.
auto_uploadbooleanfalseAuto-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_sizepos_integernoneBytes per chunk for chunked uploads.
chunk_timeoutpos_integernoneChunk timeout in milliseconds.
external(any, any -> any) | atomnoneA 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.
writeratomnoneA module, as the DSL types it. LiveView expects a function of three arguments for this option, so treat it as not working.
existingatom | (any -> any)noneHow 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.

OptionTypeDefaultDescription
labelString.t | (-> any)noneUpload label. The value is compiled into the config, but no built-in template or handler reads it.
iconString.tnoneUpload icon. The value is compiled into the config, but no built-in template or handler reads it.
classString.tnoneUpload CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
preview_classString.tnonePreview area CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
extramap%{}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 four button entities (create, update, cancel and discard) and a shared ui block. It sits at mishka_gervaz.form.submit.

OptionTypeDefaultDescription
position:top | :bottom | :both:bottomButton 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.

OptionTypeDefaultDescription
labelString.t | (-> any)noneButton label. A string, a zero-arity function, or fn state -> label end given the form state each time the buttons are drawn, so one form names its button for what the mount's defaults ask it to do.
loading_labelString.t | (-> any)noneWhat the submit button reads while its save runs, such as "Checking the connection…". String or zero-arity function. Without it the button reads "Uploading…" on a form with uploads and "Saving…" on any other.
confirmString.t | (-> any) | keywordnoneA question asked before the button acts, such as "Discard your changes?", through the browser's data-confirm. A cancel or discard button asks it only while the form holds changes. create and update ask it on every save. A string or a zero-arity function. On create and update, a keyword list is asked in the UI adapter's question window instead, before the save: title (required), body, tone (:danger, :warn or :info), answer, answer_label, confirm_label and cancel_label. Each but tone is a string or a function of the record the form edits, nil on create. See Ask before an action.
activeboolean | (any -> any)trueWhether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only.
disabledboolean | (any -> any)falseDisable button. Boolean or fn state -> boolean end.
visibleboolean | (any -> any)trueStatic or dynamic visibility. fn state -> boolean() end.
restrictedboolean | (any -> any)falseRestrict to master users with true, or decide with fn state -> boolean() end, whose true restricts it for every user, masters included, and whose false allows it for every user.

update

The update button. It sits at mishka_gervaz.form.submit.update.

OptionTypeDefaultDescription
labelString.t | (-> any)noneButton label. A string, a zero-arity function, or fn state -> label end given the form state each time the buttons are drawn, so one form names its button for what the mount's defaults ask it to do.
loading_labelString.t | (-> any)noneWhat the submit button reads while its save runs, such as "Checking the connection…". String or zero-arity function. Without it the button reads "Uploading…" on a form with uploads and "Saving…" on any other.
confirmString.t | (-> any) | keywordnoneA question asked before the button acts, such as "Discard your changes?", through the browser's data-confirm. A cancel or discard button asks it only while the form holds changes. create and update ask it on every save. A string or a zero-arity function. On create and update, a keyword list is asked in the UI adapter's question window instead, before the save: title (required), body, tone (:danger, :warn or :info), answer, answer_label, confirm_label and cancel_label. Each but tone is a string or a function of the record the form edits, nil on create. See Ask before an action.
activeboolean | (any -> any)trueWhether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only.
disabledboolean | (any -> any)falseDisable button. Boolean or fn state -> boolean end.
visibleboolean | (any -> any)trueStatic or dynamic visibility. fn state -> boolean() end.
restrictedboolean | (any -> any)falseRestrict to master users with true, or decide with fn state -> boolean() end, whose true restricts it for every user, masters included, and whose false allows it for every user.

cancel

The cancel button. It sits at mishka_gervaz.form.submit.cancel.

OptionTypeDefaultDescription
labelString.t | (-> any)noneButton label. A string, a zero-arity function, or fn state -> label end given the form state each time the buttons are drawn, so one form names its button for what the mount's defaults ask it to do.
loading_labelString.t | (-> any)noneWhat the submit button reads while its save runs, such as "Checking the connection…". String or zero-arity function. Without it the button reads "Uploading…" on a form with uploads and "Saving…" on any other.
confirmString.t | (-> any) | keywordnoneA question asked before the button acts, such as "Discard your changes?", through the browser's data-confirm. A cancel or discard button asks it only while the form holds changes. create and update ask it on every save. A string or a zero-arity function. On create and update, a keyword list is asked in the UI adapter's question window instead, before the save: title (required), body, tone (:danger, :warn or :info), answer, answer_label, confirm_label and cancel_label. Each but tone is a string or a function of the record the form edits, nil on create. See Ask before an action.
activeboolean | (any -> any)trueWhether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only.
disabledboolean | (any -> any)falseDisable button. Boolean or fn state -> boolean end.
visibleboolean | (any -> any)trueStatic or dynamic visibility. fn state -> boolean() end.
restrictedboolean | (any -> any)falseRestrict to master users with true, or decide with fn state -> boolean() end, whose true restricts it for every user, masters included, and whose false allows it for every user.

discard

The discard button. It is drawn beside Save while the form holds changes, and puts the form back to its starting values: an edit reads its record again, and a create starts over empty with the mount's defaults. A :tabs form stays on its tab. Without a discard block there is no such button. It sits at mishka_gervaz.form.submit.discard.

OptionTypeDefaultDescription
labelString.t | (-> any)noneButton label. A string, a zero-arity function, or fn state -> label end given the form state each time the buttons are drawn, so one form names its button for what the mount's defaults ask it to do.
loading_labelString.t | (-> any)noneWhat the submit button reads while its save runs, such as "Checking the connection…". String or zero-arity function. Without it the button reads "Uploading…" on a form with uploads and "Saving…" on any other.
confirmString.t | (-> any) | keywordnoneA question asked before the button acts, such as "Discard your changes?", through the browser's data-confirm. A cancel or discard button asks it only while the form holds changes. create and update ask it on every save. A string or a zero-arity function. On create and update, a keyword list is asked in the UI adapter's question window instead, before the save: title (required), body, tone (:danger, :warn or :info), answer, answer_label, confirm_label and cancel_label. Each but tone is a string or a function of the record the form edits, nil on create. See Ask before an action.
activeboolean | (any -> any)trueWhether the button is active. Boolean or fn state -> boolean end. Set to false to suppress a button inherited from the domain. Resource-only.
disabledboolean | (any -> any)falseDisable button. Boolean or fn state -> boolean end.
visibleboolean | (any -> any)trueStatic or dynamic visibility. fn state -> boolean() end.
restrictedboolean | (any -> any)falseRestrict to master users with true, or decide with fn state -> boolean() end, whose true restricts it for every user, masters included, and whose false allows it for every user.

submit ui

Classes for the submit row. It sits at mishka_gervaz.form.submit.ui.

OptionTypeDefaultDescription
submit_classString.tnoneSubmit button CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
cancel_classString.tnoneCancel button CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
wrapper_classString.tnoneButton wrapper CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
extramap%{}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.

OptionTypeDefaultDescription
debounceintegernoneDefault debounce milliseconds for all fields. Overridden per-field via ui do debounce end.
templateatomMishkaGervaz.Form.Templates.StandardThe form template module. Built in: MishkaGervaz.Form.Templates.Standard, which draws all three layout modes.
ui_adapteratomMishkaGervaz.UIAdapters.TailwindThe UI adapter module that draws inputs, groups and buttons. One adapter serves both tables and forms.
ui_adapter_optskeyword[]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):allThe 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.

OptionTypeDefaultDescription
form_classString.tnoneForm element CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
field_classString.tnoneDefault field CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
label_classString.tnoneDefault label CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
error_classString.tnoneError message CSS classes. The value is compiled into the config, but no built-in template or handler reads it.
extramap%{}Template-specific theming options. The value is compiled into the config, but no built-in template or handler reads it.