@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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 7.1.43
4
+
5
+ * [Validator]: Add max file size validation
6
+
3
7
  ## 7.1.42
4
8
 
5
9
  * [Popin]: Add popin element in callback function param
@@ -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
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.42
3
+ @version: 7.1.43
4
4
 
5
5
 
6
6
  ## Use
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.42",
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": [],