feat: add client-side filesize check to file component #52
Loading…
Reference in a new issue
No description provided.
Delete branch "github/fork/euzghe/v1"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I've implemented a client-side file size check using Alpine.js. This ensures that users cannot upload files larger than the specified maxSize. If a file is too large, it alerts the user and clears the input.
Fixes #20
Please avoid using alert() for validation errors.
We already render validation messages below the input with the
text-dangerclass (line 48–49).Also, please do not hardcode the error message in English.
The project uses Laravel translations, so the message should come from the language files.
I will add the German translation on my side.
I suggest changing maxSize to null by default.
A default limit of 2048 KB enforces behavior that may not be desired for all usages.
The inline comment can be removed, the intent of maxSize is already clear.
The inline comment can be removed.
The conversion from KB to bytes is self explanatory and does not need a comment.
Remove this comment.
Clearing the file input value is clear without explanation.
This translations does not exists in Laravel (See: https://github.com/laravel/framework/blob/12.x/src/Illuminate/Translation/lang/en/validation.php#L101)
You can use this one instead:
The original div with
x-show="errorMessage"is outside thex-datascope. That prevents AlpineJS error messages from showing. The easiest fix is to move this code to the end of thex-datadiv (after the input, Line 45).Here is an approach that ensures only 1 validation message is shown at a time:
We can then remove the old validation (Line: 55-58).