@creative-web-solution/front-library 7.1.42 → 7.1.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/Modules/Validator/MaxFileSize.ts +30 -0
- package/README.md +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { addValidator } from './index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* File size validation
|
|
5
|
+
*/
|
|
6
|
+
addValidator( 'maxfilesize', '[data-max-file-size]', ( $input, value, isLiveValidation ) => {
|
|
7
|
+
if (!($input as HTMLInputElement).files?.length) {
|
|
8
|
+
return Promise.resolve({
|
|
9
|
+
$input,
|
|
10
|
+
value,
|
|
11
|
+
"isValid": true,
|
|
12
|
+
"label": "maxfilesize",
|
|
13
|
+
isLiveValidation
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const size = ($input as HTMLInputElement).files![0].size;
|
|
18
|
+
const maxSize = Number($input.getAttribute('data-max-file-size') ?? "0");
|
|
19
|
+
console.log({size, maxSize})
|
|
20
|
+
return Promise.resolve({
|
|
21
|
+
$input,
|
|
22
|
+
value,
|
|
23
|
+
"isValid": ($input as HTMLInputElement).files?.length === 0 ||
|
|
24
|
+
size <= 0 ||
|
|
25
|
+
maxSize <= 0 ||
|
|
26
|
+
size <= maxSize,
|
|
27
|
+
"label": "maxfilesize",
|
|
28
|
+
isLiveValidation
|
|
29
|
+
});
|
|
30
|
+
} );
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@creative-web-solution/front-library",
|
|
3
3
|
"title": "Frontend library",
|
|
4
4
|
"description": "Frontend functions and modules",
|
|
5
|
-
"version": "7.1.
|
|
5
|
+
"version": "7.1.43",
|
|
6
6
|
"homepage": "https://github.com/creative-web-solution/front-library",
|
|
7
7
|
"author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
|
|
8
8
|
"keywords": [],
|