@cedarjs/forms 7.0.0-canary.3211 → 7.0.0-canary.3215
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/dist/coercion.d.ts.map +1 -1
- package/dist/coercion.js +19 -1
- package/package.json +2 -2
package/dist/coercion.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coercion.d.ts","sourceRoot":"","sources":["../src/coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"coercion.d.ts","sourceRoot":"","sources":["../src/coercion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,eAAe,EAAY,MAAM,iBAAiB,CAAA;AAE7E;;;;;;GAMG;AACH,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB,CAAA;AAKD;;;;;;GAMG;AAEH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,WAAW,GAAG,CAAC,GAAG,EAAE,CAAA;AA2KtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,eAAO,MAAM,WAAW,GACtB,YAAY,sBAAsB,EAClC,yBAAyB,gBAAgB,SAyE1C,CAAA"}
|
package/dist/coercion.js
CHANGED
|
@@ -117,6 +117,7 @@ const getSetValueAsFn = (type, emptyAs, required, isId) => {
|
|
|
117
117
|
return fn;
|
|
118
118
|
};
|
|
119
119
|
const JSONValidation = (val) => typeof val === "number" ? !isNaN(val) : true;
|
|
120
|
+
const JSON_VALIDATION_KEY = "validJSON";
|
|
120
121
|
const setCoercion = (validation, { type, name, emptyAs }) => {
|
|
121
122
|
if (validation.setValueAs) {
|
|
122
123
|
return;
|
|
@@ -125,7 +126,24 @@ const setCoercion = (validation, { type, name, emptyAs }) => {
|
|
|
125
126
|
if (validation.valueAsBoolean || type === "checkbox") {
|
|
126
127
|
return;
|
|
127
128
|
} else if (validation.valueAsJSON) {
|
|
128
|
-
validation.validate
|
|
129
|
+
const userValidate = validation.validate;
|
|
130
|
+
const userValidators = typeof userValidate === "function" ? { validate: userValidate } : { ...userValidate };
|
|
131
|
+
let jsonValidationKey = JSON_VALIDATION_KEY;
|
|
132
|
+
while (jsonValidationKey in userValidators) {
|
|
133
|
+
jsonValidationKey = `_${jsonValidationKey}`;
|
|
134
|
+
}
|
|
135
|
+
const guardedValidators = Object.fromEntries(
|
|
136
|
+
Object.entries(userValidators).map(
|
|
137
|
+
([key, validator]) => [
|
|
138
|
+
key,
|
|
139
|
+
(value, formValues) => JSONValidation(value) ? validator(value, formValues) : true
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
);
|
|
143
|
+
validation.validate = {
|
|
144
|
+
[jsonValidationKey]: JSONValidation,
|
|
145
|
+
...guardedValidators
|
|
146
|
+
};
|
|
129
147
|
delete validation.valueAsJSON;
|
|
130
148
|
valueAs = "valueAsJSON";
|
|
131
149
|
} else if (type === "date" || type === "datetime-local" || validation.valueAsDate) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/forms",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.3215",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/cedarjs/cedar.git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"react-hook-form": "7.88.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@cedarjs/framework-tools": "7.0.0-canary.
|
|
39
|
+
"@cedarjs/framework-tools": "7.0.0-canary.3215",
|
|
40
40
|
"@testing-library/dom": "10.4.1",
|
|
41
41
|
"@testing-library/jest-dom": "6.9.1",
|
|
42
42
|
"@testing-library/react": "16.3.3",
|