@juantroconisf/lib 2.2.3 → 2.2.5
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/index.js +3 -6
- package/dist/index.mjs +3 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -37,7 +37,6 @@ var NextUIError = class {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/utils.ts
|
|
40
|
-
var getNestedValueByKey = (obj, nestedKey) => nestedKey.split(".").reduce((acc, key) => acc[key], obj);
|
|
41
40
|
function handleNestedChange({
|
|
42
41
|
state,
|
|
43
42
|
id,
|
|
@@ -69,7 +68,7 @@ var regex = {
|
|
|
69
68
|
};
|
|
70
69
|
var errors = {
|
|
71
70
|
required: {
|
|
72
|
-
validate: (val) => Boolean(val),
|
|
71
|
+
validate: (val, isRequired) => !isRequired || Boolean(val),
|
|
73
72
|
msg: "REQUIRED"
|
|
74
73
|
},
|
|
75
74
|
min: {
|
|
@@ -148,7 +147,7 @@ function useComponentLanguage() {
|
|
|
148
147
|
function useValidation() {
|
|
149
148
|
const { lang } = useComponentLanguage();
|
|
150
149
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
151
|
-
const items = Object.entries(types), isRequired = items.some(([key]) => key === "required");
|
|
150
|
+
const items = Object.entries(types), isRequired = items.some(([key, val]) => key === "required" && val);
|
|
152
151
|
if (isRequired && !isTouched)
|
|
153
152
|
return {
|
|
154
153
|
isValid: true,
|
|
@@ -183,9 +182,7 @@ function useFormChange(initialObj) {
|
|
|
183
182
|
setState(initialObj);
|
|
184
183
|
};
|
|
185
184
|
function register(id, validations, errorMessages) {
|
|
186
|
-
const [value, isTouched] = [state, touched]
|
|
187
|
-
(obj) => getNestedValueByKey(obj, id)
|
|
188
|
-
), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
185
|
+
const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
189
186
|
errors2 = handleNestedChange({
|
|
190
187
|
state: errors2,
|
|
191
188
|
id,
|
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,6 @@ var NextUIError = class {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
// src/utils.ts
|
|
22
|
-
var getNestedValueByKey = (obj, nestedKey) => nestedKey.split(".").reduce((acc, key) => acc[key], obj);
|
|
23
22
|
function handleNestedChange({
|
|
24
23
|
state,
|
|
25
24
|
id,
|
|
@@ -51,7 +50,7 @@ var regex = {
|
|
|
51
50
|
};
|
|
52
51
|
var errors = {
|
|
53
52
|
required: {
|
|
54
|
-
validate: (val) => Boolean(val),
|
|
53
|
+
validate: (val, isRequired) => !isRequired || Boolean(val),
|
|
55
54
|
msg: "REQUIRED"
|
|
56
55
|
},
|
|
57
56
|
min: {
|
|
@@ -130,7 +129,7 @@ function useComponentLanguage() {
|
|
|
130
129
|
function useValidation() {
|
|
131
130
|
const { lang } = useComponentLanguage();
|
|
132
131
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
133
|
-
const items = Object.entries(types), isRequired = items.some(([key]) => key === "required");
|
|
132
|
+
const items = Object.entries(types), isRequired = items.some(([key, val]) => key === "required" && val);
|
|
134
133
|
if (isRequired && !isTouched)
|
|
135
134
|
return {
|
|
136
135
|
isValid: true,
|
|
@@ -165,9 +164,7 @@ function useFormChange(initialObj) {
|
|
|
165
164
|
setState(initialObj);
|
|
166
165
|
};
|
|
167
166
|
function register(id, validations, errorMessages) {
|
|
168
|
-
const [value, isTouched] = [state, touched]
|
|
169
|
-
(obj) => getNestedValueByKey(obj, id)
|
|
170
|
-
), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
167
|
+
const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
171
168
|
errors2 = handleNestedChange({
|
|
172
169
|
state: errors2,
|
|
173
170
|
id,
|