Usage

HTML (Auto-init)

HTML
<input type="file" class="fw-fileupload" id="myFile">

<script>
  FormWidgets.autoInit();
</script>

HTML with Data Attributes

HTML
<input type="file" class="fw-fileupload"
       data-accept="image/*"
       data-max-size="5242880">

JavaScript Initialization

JavaScript
// Images only, 2MB max
FormWidgets.init('#myFile', 'FileUpload', {
    accept: 'image/*',
    maxSize: 2097152   // 2MB in bytes
});

// PDF only, 10MB max
FormWidgets.init('#pdfFile', 'FileUpload', {
    accept: '.pdf,application/pdf',
    maxSize: 10485760  // 10MB in bytes
});

Options

OptionTypeDefaultDescription
maxSizenumbernullMaximum allowed file size in bytes. Files exceeding this limit show a validation error.
acceptstring''Comma-separated list of accepted file types. Follows the HTML accept attribute syntax (e.g. image/*, .pdf,.docx).
iconstring'upload'Name of the SVG icon to use from the internal icon set.
requiredbooleanfalseMarks the field as required.

Data Attributes

Data AttributeEquivalent OptionExample
data-acceptacceptdata-accept="image/*"
data-max-sizemaxSizedata-max-size="5242880"
data-requiredrequireddata-required="true"

Common File Size Values

SizeBytesmaxSize value
500 KB512,000512000
1 MB1,048,5761048576
2 MB2,097,1522097152
5 MB5,242,8805242880
10 MB10,485,76010485760
25 MB26,214,40026214400

Common Accept Values

ValueAccepts
image/*All image types (JPEG, PNG, GIF, WebP, etc.)
image/jpeg,image/pngJPEG and PNG only
.pdfPDF files
.pdf,application/pdfPDF files (more compatible)
.doc,.docxWord documents
.xls,.xlsxExcel spreadsheets
.pdf,.doc,.docxPDF and Word documents
video/*All video types
audio/*All audio types
.zip,.tar,.gzArchive files

Features

Size Validation

Files exceeding maxSize show an inline error message.

Type Filtering

Use accept to restrict file types — the file dialog filters automatically.

Visual Feedback

Shows the selected filename after a file is chosen.

Consistent Styling

Matches all other FormWidget fields for a unified appearance.