@cocreate/validation 1.14.1 → 1.15.1
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 +21 -0
- package/package.json +1 -1
- package/src/index.js +5 -1
- package/src/validations/email.js +31 -0
- package/src/validations/length.js +31 -0
- package/src/validations/matches.js +3 -3
- package/src/validations/required.js +5 -5
- package/src/validations/subdomain.js +3 -3
- package/src/validations/unique.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.15.1](https://github.com/CoCreate-app/CoCreate-validation/compare/v1.15.0...v1.15.1) (2024-01-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* template selector ([b135e76](https://github.com/CoCreate-app/CoCreate-validation/commit/b135e76a4e123ae86fc304a8807152ee938baffe))
|
|
7
|
+
|
|
8
|
+
# [1.15.0](https://github.com/CoCreate-app/CoCreate-validation/compare/v1.14.1...v1.15.0) (2023-12-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* initialize length and email validations ([7cace75](https://github.com/CoCreate-app/CoCreate-validation/commit/7cace75c62a054ce23a7f8f03dc68736387ef2bb))
|
|
14
|
+
* render property ([93e3040](https://github.com/CoCreate-app/CoCreate-validation/commit/93e3040d12407ea95693f2fbd6544dd6bf70b4fb))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* email validation ([c950a32](https://github.com/CoCreate-app/CoCreate-validation/commit/c950a3215536eef27f1110d3fe10466c8d9c346e))
|
|
20
|
+
* length validation ([591b2b8](https://github.com/CoCreate-app/CoCreate-validation/commit/591b2b811d597a909c6d0eb0020ca6857224d66d))
|
|
21
|
+
|
|
1
22
|
## [1.14.1](https://github.com/CoCreate-app/CoCreate-validation/compare/v1.14.0...v1.14.1) (2023-12-15)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -12,14 +12,18 @@ import { matches } from './validations/matches';
|
|
|
12
12
|
import { required } from './validations/required';
|
|
13
13
|
import { unique } from './validations/unique';
|
|
14
14
|
import { subdomain } from './validations/subdomain';
|
|
15
|
+
import { length } from './validations/length';
|
|
16
|
+
import { email } from './validations/email';
|
|
15
17
|
|
|
16
18
|
const validations = new Map();
|
|
17
19
|
validations.set('matches', matches);
|
|
18
20
|
validations.set('required', required);
|
|
19
21
|
validations.set('subdomain', subdomain);
|
|
20
22
|
validations.set('unique', unique);
|
|
23
|
+
validations.set('length', length);
|
|
24
|
+
validations.set('email', email);
|
|
21
25
|
|
|
22
|
-
const selectors = '[matches], [required], [unique], [subdomain]';
|
|
26
|
+
const selectors = '[matches], [required], [unique], [subdomain], [length], [email]';
|
|
23
27
|
|
|
24
28
|
async function validate(btn, params) {
|
|
25
29
|
let validateElements;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { render } from '@cocreate/render';
|
|
2
|
+
|
|
3
|
+
export var email = async (elements) => {
|
|
4
|
+
let failedElements = [];
|
|
5
|
+
for (let element of elements) {
|
|
6
|
+
let length = element.getAttribute('length') || 0
|
|
7
|
+
length = parseFloat(length)
|
|
8
|
+
let value = await element.getValue();
|
|
9
|
+
let isValidEmail = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(value);
|
|
10
|
+
|
|
11
|
+
if (isValidEmail) {
|
|
12
|
+
element.setAttribute('validation', 'true');
|
|
13
|
+
} else {
|
|
14
|
+
element.setAttribute('validation', 'false');
|
|
15
|
+
failedElements.push(element);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (failedElements.length) {
|
|
19
|
+
render({
|
|
20
|
+
selector: "[template*='validate']",
|
|
21
|
+
data: [{
|
|
22
|
+
type: 'email',
|
|
23
|
+
status: 'failed',
|
|
24
|
+
message: 'Please enter a valid email address',
|
|
25
|
+
selector: '[required][validation="false"]',
|
|
26
|
+
elements: failedElements
|
|
27
|
+
}]
|
|
28
|
+
});
|
|
29
|
+
return failedElements;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { render } from '@cocreate/render';
|
|
2
|
+
|
|
3
|
+
export var length = async (elements) => {
|
|
4
|
+
let failedElements = [];
|
|
5
|
+
for (let element of elements) {
|
|
6
|
+
let length = element.getAttribute('length') || 0
|
|
7
|
+
length = parseFloat(length)
|
|
8
|
+
let value = await element.getValue();
|
|
9
|
+
if (element.type === 'password')
|
|
10
|
+
value = atob(value)
|
|
11
|
+
if (value.length >= length) {
|
|
12
|
+
element.setAttribute('validation', 'true');
|
|
13
|
+
} else {
|
|
14
|
+
element.setAttribute('validation', 'false');
|
|
15
|
+
failedElements.push(element);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (failedElements.length) {
|
|
19
|
+
render({
|
|
20
|
+
selector: "[template*='validate']",
|
|
21
|
+
data: [{
|
|
22
|
+
type: 'length',
|
|
23
|
+
status: 'failed',
|
|
24
|
+
message: 'Does not meet the minimum character length requirement',
|
|
25
|
+
selector: '[required][validation="false"]',
|
|
26
|
+
elements: failedElements
|
|
27
|
+
}]
|
|
28
|
+
});
|
|
29
|
+
return failedElements;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
@@ -37,14 +37,14 @@ function matches(elements) {
|
|
|
37
37
|
}
|
|
38
38
|
if (failedElements.length) {
|
|
39
39
|
render({
|
|
40
|
-
selector: "[template
|
|
41
|
-
data: {
|
|
40
|
+
selector: "[template*='validate']",
|
|
41
|
+
data: [{
|
|
42
42
|
type: 'matches',
|
|
43
43
|
status: 'failed',
|
|
44
44
|
message: 'One or more values do not match',
|
|
45
45
|
selector: '[matches][validation="false"]',
|
|
46
46
|
elements: failedElements
|
|
47
|
-
}
|
|
47
|
+
}]
|
|
48
48
|
});
|
|
49
49
|
return failedElements;
|
|
50
50
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// import {validations} from '../index.js';
|
|
2
|
-
import render from '@cocreate/render';
|
|
2
|
+
import { render } from '@cocreate/render';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export var required = async (elements) => {
|
|
@@ -15,15 +15,15 @@ export var required = async (elements) => {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
if (failedElements.length) {
|
|
18
|
-
render
|
|
19
|
-
selector: "[template
|
|
20
|
-
data: {
|
|
18
|
+
render({
|
|
19
|
+
selector: "[template*='validate']",
|
|
20
|
+
data: [{
|
|
21
21
|
type: 'unique',
|
|
22
22
|
status: 'failed',
|
|
23
23
|
message: 'One or more required fields are missing values',
|
|
24
24
|
selector: '[required][validation="false"]',
|
|
25
25
|
elements: failedElements
|
|
26
|
-
}
|
|
26
|
+
}]
|
|
27
27
|
});
|
|
28
28
|
return failedElements;
|
|
29
29
|
}
|
|
@@ -47,14 +47,14 @@ function subdomain(elements) {
|
|
|
47
47
|
}
|
|
48
48
|
if (failedElements.length) {
|
|
49
49
|
render({
|
|
50
|
-
selector: "[template
|
|
51
|
-
data: {
|
|
50
|
+
selector: "[template*='validate']",
|
|
51
|
+
data: [{
|
|
52
52
|
type: 'subdomain',
|
|
53
53
|
status: 'failed',
|
|
54
54
|
message: 'Enter a valid subdomain. subdomain can only be one level.',
|
|
55
55
|
selector: '[subdomain][validation="false"]',
|
|
56
56
|
elements: failedElements
|
|
57
|
-
}
|
|
57
|
+
}]
|
|
58
58
|
});
|
|
59
59
|
return failedElements;
|
|
60
60
|
}
|
|
@@ -10,14 +10,14 @@ export const unique = (elements) => {
|
|
|
10
10
|
}
|
|
11
11
|
if (failedElements.length) {
|
|
12
12
|
render({
|
|
13
|
-
selector: "[template
|
|
14
|
-
data: {
|
|
13
|
+
selector: "[template*='validate']",
|
|
14
|
+
data: [{
|
|
15
15
|
type: 'unique',
|
|
16
16
|
status: 'failed',
|
|
17
17
|
message: 'One or more values are not unique',
|
|
18
18
|
selector: '[unique="false"]',
|
|
19
19
|
elements: failedElements
|
|
20
|
-
}
|
|
20
|
+
}]
|
|
21
21
|
});
|
|
22
22
|
return failedElements;
|
|
23
23
|
}
|