Constructor
new FileSizeValidatorController()
Multiple Files
```html
<input type="file"
multiple
data-file-size-validator-target="fileInput"
data-action="change->file-size-validator#validateFiles">
```Custom Total Limit
```html
<div data-controller="file-size-validator"
data-file-size-validator-max-size-value="26214400"
data-file-size-validator-total-max-size-value="52428800">
```Methods
buildInvalidFilesMessage(invalidFiles) → {string}
Build error message for invalid files
| Name | Type | Description |
|---|---|---|
invalidFiles | Array | Array of invalid file objects |
Error message with HTML-escaped file names
- Type:
- string
buildTotalSizeWarningMessage(totalSize, fileCount) → {string}
Build warning message for total size
| Name | Type | Description |
|---|---|---|
totalSize | number | Total size in bytes |
fileCount | number | Number of files |
Warning message
- Type:
- string
checkFileSizes(files) → {Object}
Check file sizes and return validation result
| Name | Type | Description |
|---|---|---|
files | Array.<File> | Array of File objects |
Validation result
- Type:
- Object
clearWarning()
Clear warning message
connect()
Initialize controller
disableSubmit()
Disable submit button
dispatch(eventName, options)
Dispatch custom event
| Name | Type | Description |
|---|---|---|
eventName | string | Event name (without prefix) |
options | Object | Event options |
enableSubmit()
Enable submit button
escapeHtml(str) → {string}
Escape HTML special characters to prevent XSS
| Name | Type | Description |
|---|---|---|
str | string | String to escape |
Escaped string
- Type:
- string
formatBytes(bytes, decimals) → {string}
Format bytes to human-readable string
| Name | Type | Default | Description |
|---|---|---|---|
bytes | number | Size in bytes | |
decimals | number | 2 | Number of decimal places |
Formatted size string
- Type:
- string
formatWarningMessage(message, type) → {string}
Format warning message with icon
| Name | Type | Default | Description |
|---|---|---|---|
message | string | Warning message | |
type | string | warning | Message type ('error' or 'warning') |
Formatted HTML
- Type:
- string
showInvalidFilesWarning(validation)
Show warning for invalid files
| Name | Type | Description |
|---|---|---|
validation | Object | Validation result |
showTotalSizeWarning(validation)
Show warning for total size
| Name | Type | Description |
|---|---|---|
validation | Object | Validation result |
validateFiles(event)
Validate selected files
| Name | Type | Description |
|---|---|---|
event | Event | File input change event |