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:

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 three button entities 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. String or zero-arity function.
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. true or fn state -> boolean() end.

update

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

OptionTypeDefaultDescription
labelString.t | (-> any)noneButton label. String or zero-arity function.
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. true or fn state -> boolean() end.

cancel

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

OptionTypeDefaultDescription
labelString.t | (-> any)noneButton label. String or zero-arity function.
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. true or fn state -> boolean() end.

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.