File Uploader HTML forms handling
We provide the dedicated element uc-form-input to handle HTML forms with the
File Uploader. This is useful when you use the File Uploader within the HTML
form with the native client-side (browser) validation.
In the case of rich-featured forms with custom validation and inline errors rendering, it’s better to use directly Events and/or API to extract data from the File Uploader.
Usage
The only attribute that uc-form-input tag requires is ctx-name, see
Context for more details.
It could be placed anywhere on the page. However, we recommend placing it inside the File Uploader to make it able to align native validation messages within the File Uploader button.
It supports three modes:
- Multiple separate inputs for each file.
- Single input for the group of files.
- Single input for a single file.
The current mode is defined by the
group-output and
multiple attributes on the
uc-config tag.
Separate inputs for each file
In this mode, each file will be represented by its own input. It is useful when you need to handle each file separately.
Every input will have the name of the ctx-name attribute with the [] suffix.
Here is the example of the output FormData entries:
In the example above, my-uploader is the ctx-name attribute value.
One input for the group of files
In this mode, all files will be represented by a single input. It is useful when you need to handle all files as a group.
The input will have the name of the ctx-name.
Here is the example of the output FormData entries:
In the example above, my-uploader is the ctx-name attribute value.
One input for a single file
When multiple is off and group-output is not set, the uploaded file is
represented by a single input named after the ctx-name, without the []
suffix.
Here is the example of the output FormData entries:
Configuration
As it was mentioned above, the only attribute that uc-form-input tag requires
is ctx-name. The optional name attribute sets the input name used instead of
the ctx-name, with the same [] suffix rule.
It also relies on a few attributes of the uc-config tag:
group-outputandmultiple: define the behaviour mode (single input for the group of files, single input for a single file, or multiple inputs for each file).multiple-min: if it is greater than 0, the input will be required, preventing the form from submitting until the required number of files is uploaded.
Example
Here is the example of the HTML form with the File Uploader:
Get YOUR_PUBLIC_KEY from API keys.