@cocreate/validation 1.11.6 → 1.11.8
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 +14 -0
- package/package.json +1 -1
- package/src/index.js +4 -4
- package/src/validations/matches.js +22 -22
- package/src/validations/required.js +2 -2
- package/src/validations/subdomain.js +2 -2
- package/src/validations/unique.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.11.8](https://github.com/CoCreate-app/CoCreate-validation/compare/v1.11.7...v1.11.8) (2023-10-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* actions ([6a8b1fa](https://github.com/CoCreate-app/CoCreate-validation/commit/6a8b1fab566c6be04fc3b87625658ff5510d14ce))
|
|
7
|
+
|
|
8
|
+
## [1.11.7](https://github.com/CoCreate-app/CoCreate-validation/compare/v1.11.6...v1.11.7) (2023-10-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* declartion of render functions using object spread ([b51b172](https://github.com/CoCreate-app/CoCreate-validation/commit/b51b17283c46c6c777d70f4f1ad853cec9100caf))
|
|
14
|
+
|
|
1
15
|
## [1.11.6](https://github.com/CoCreate-app/CoCreate-validation/compare/v1.11.5...v1.11.6) (2023-10-17)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
********************************************************************************/
|
|
7
7
|
|
|
8
8
|
/*globals CustomEvent*/
|
|
9
|
-
import
|
|
9
|
+
import actions from '@cocreate/actions';
|
|
10
10
|
// import render from '@cocreate/render';
|
|
11
11
|
import { matches } from './validations/matches';
|
|
12
12
|
import { required } from './validations/required';
|
|
@@ -72,10 +72,10 @@ async function validate(btn, params) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
actions.init({
|
|
76
76
|
name: "validate",
|
|
77
|
-
callback: (
|
|
78
|
-
validate(
|
|
77
|
+
callback: (action) => {
|
|
78
|
+
validate(action.element, action.params);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import render from '@cocreate/render';
|
|
1
|
+
import { render } from '@cocreate/render';
|
|
2
2
|
|
|
3
|
-
function initMatches(){
|
|
3
|
+
function initMatches() {
|
|
4
4
|
let elements = document.querySelectorAll('[matches]');
|
|
5
|
-
for (let element of elements){
|
|
5
|
+
for (let element of elements) {
|
|
6
6
|
let targetSelector = element.getAttribute('matches');
|
|
7
7
|
let target = document.querySelector(targetSelector);
|
|
8
|
-
element.validations = {matches: target};
|
|
8
|
+
element.validations = { matches: target };
|
|
9
9
|
element.addEventListener('input', validateMatchEvent);
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function validateMatchEvent(e){
|
|
13
|
+
function validateMatchEvent(e) {
|
|
14
14
|
validateMatch(e.target);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function validateMatch(element){
|
|
17
|
+
function validateMatch(element) {
|
|
18
18
|
// let element = e.target;
|
|
19
19
|
let target = element.validations.matches;
|
|
20
|
-
if (target.value == element.value){
|
|
20
|
+
if (target.value == element.value) {
|
|
21
21
|
target.setAttribute('validation', 'true');
|
|
22
22
|
element.setAttribute('validation', 'true');
|
|
23
23
|
}
|
|
@@ -27,29 +27,29 @@ function validateMatch(element){
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
function matches(elements){
|
|
30
|
+
function matches(elements) {
|
|
31
31
|
let failedElements = [];
|
|
32
32
|
for (let element of elements) {
|
|
33
33
|
let isValid = element.getAttribute('validation');
|
|
34
|
-
if (isValid == 'false'){
|
|
34
|
+
if (isValid == 'false') {
|
|
35
35
|
failedElements.push(element);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
if (failedElements.length){
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
if (failedElements.length) {
|
|
39
|
+
render({
|
|
40
|
+
selector: "[template='validate']",
|
|
41
|
+
data: {
|
|
42
|
+
type: 'matches',
|
|
43
|
+
status: 'failed',
|
|
44
|
+
message: 'One or more values do not match',
|
|
45
|
+
selector: '[matches][validation="false"]',
|
|
46
|
+
elements: failedElements
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return failedElements;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
initMatches();
|
|
54
54
|
|
|
55
|
-
export {matches};
|
|
55
|
+
export { matches };
|
|
@@ -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,7 +15,7 @@ export var required = async (elements) => {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
if (failedElements.length) {
|
|
18
|
-
render
|
|
18
|
+
render({
|
|
19
19
|
selector: "[template='validate']",
|
|
20
20
|
data: {
|
|
21
21
|
type: 'unique',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import render from '@cocreate/render';
|
|
1
|
+
import { render } from '@cocreate/render';
|
|
2
2
|
|
|
3
3
|
function initSubdomain() {
|
|
4
4
|
let elements = document.querySelectorAll('[subdomain]');
|
|
@@ -46,7 +46,7 @@ function subdomain(elements) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
if (failedElements.length) {
|
|
49
|
-
render
|
|
49
|
+
render({
|
|
50
50
|
selector: "[template='validate']",
|
|
51
51
|
data: {
|
|
52
52
|
type: 'subdomain',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import render from '@cocreate/render';
|
|
1
|
+
import { render } from '@cocreate/render';
|
|
2
2
|
|
|
3
3
|
export const unique = (elements) => {
|
|
4
4
|
let failedElements = [];
|
|
@@ -9,7 +9,7 @@ export const unique = (elements) => {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
if (failedElements.length) {
|
|
12
|
-
render
|
|
12
|
+
render({
|
|
13
13
|
selector: "[template='validate']",
|
|
14
14
|
data: {
|
|
15
15
|
type: 'unique',
|