@juantroconisf/lib 3.2.3 → 3.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.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -5
- package/dist/index.mjs +7 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -103,6 +103,8 @@ interface UseFormChangeResponse<O extends StateType> {
|
|
|
103
103
|
hasInvalidValues: () => boolean;
|
|
104
104
|
touched: TouchedType<O>;
|
|
105
105
|
resetForm: () => void;
|
|
106
|
+
errors: React.RefObject<TouchedType<O>>;
|
|
107
|
+
realErrors: React.RefObject<TouchedType<O>>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
|
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ interface UseFormChangeResponse<O extends StateType> {
|
|
|
103
103
|
hasInvalidValues: () => boolean;
|
|
104
104
|
touched: TouchedType<O>;
|
|
105
105
|
resetForm: () => void;
|
|
106
|
+
errors: React.RefObject<TouchedType<O>>;
|
|
107
|
+
realErrors: React.RefObject<TouchedType<O>>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
|
package/dist/index.js
CHANGED
|
@@ -181,7 +181,7 @@ function useFormChange({
|
|
|
181
181
|
validations,
|
|
182
182
|
errorMessages
|
|
183
183
|
}) {
|
|
184
|
-
const [state, setState] = (0, import_react.useState)(newState), falseState = allToValue(state, false), [touched, setTouched] = (0, import_react.useState)(falseState), errors2 = (0, import_react.useRef)({ ...falseState }),
|
|
184
|
+
const [state, setState] = (0, import_react.useState)(newState), falseState = allToValue(state, false), [touched, setTouched] = (0, import_react.useState)(falseState), errors2 = (0, import_react.useRef)({ ...falseState }), realErrors = (0, import_react.useRef)({ ...falseState }), { getValidation } = useValidation();
|
|
185
185
|
const onBlur = (id) => setTouched(
|
|
186
186
|
handleNestedChange({ state: touched, id, value: true })
|
|
187
187
|
), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) => setState(
|
|
@@ -199,14 +199,13 @@ function useFormChange({
|
|
|
199
199
|
isInvalid: false,
|
|
200
200
|
errorMessage: ""
|
|
201
201
|
};
|
|
202
|
-
if (requirements === void 0) return props;
|
|
203
202
|
const [ui] = [
|
|
204
203
|
{
|
|
205
204
|
ref: errors2,
|
|
206
205
|
touched: isTouched
|
|
207
206
|
},
|
|
208
207
|
{
|
|
209
|
-
ref:
|
|
208
|
+
ref: realErrors,
|
|
210
209
|
touched: true
|
|
211
210
|
}
|
|
212
211
|
].map((item) => {
|
|
@@ -223,6 +222,7 @@ function useFormChange({
|
|
|
223
222
|
});
|
|
224
223
|
return req;
|
|
225
224
|
});
|
|
225
|
+
if (requirements === void 0) return props;
|
|
226
226
|
return {
|
|
227
227
|
...props,
|
|
228
228
|
isInvalid: !ui.isValid,
|
|
@@ -260,7 +260,7 @@ function useFormChange({
|
|
|
260
260
|
),
|
|
261
261
|
hasInvalidValues: () => {
|
|
262
262
|
setTouched(allToValue(touched, true));
|
|
263
|
-
return JSON.stringify(
|
|
263
|
+
return JSON.stringify(realErrors.current).includes(":true");
|
|
264
264
|
},
|
|
265
265
|
touched,
|
|
266
266
|
resetForm: () => {
|
|
@@ -268,7 +268,9 @@ function useFormChange({
|
|
|
268
268
|
setTouched(val);
|
|
269
269
|
errors2.current = val;
|
|
270
270
|
setState(newState);
|
|
271
|
-
}
|
|
271
|
+
},
|
|
272
|
+
errors: errors2,
|
|
273
|
+
realErrors
|
|
272
274
|
};
|
|
273
275
|
}
|
|
274
276
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -162,7 +162,7 @@ function useFormChange({
|
|
|
162
162
|
validations,
|
|
163
163
|
errorMessages
|
|
164
164
|
}) {
|
|
165
|
-
const [state, setState] = useState(newState), falseState = allToValue(state, false), [touched, setTouched] = useState(falseState), errors2 = useRef({ ...falseState }),
|
|
165
|
+
const [state, setState] = useState(newState), falseState = allToValue(state, false), [touched, setTouched] = useState(falseState), errors2 = useRef({ ...falseState }), realErrors = useRef({ ...falseState }), { getValidation } = useValidation();
|
|
166
166
|
const onBlur = (id) => setTouched(
|
|
167
167
|
handleNestedChange({ state: touched, id, value: true })
|
|
168
168
|
), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) => setState(
|
|
@@ -180,14 +180,13 @@ function useFormChange({
|
|
|
180
180
|
isInvalid: false,
|
|
181
181
|
errorMessage: ""
|
|
182
182
|
};
|
|
183
|
-
if (requirements === void 0) return props;
|
|
184
183
|
const [ui] = [
|
|
185
184
|
{
|
|
186
185
|
ref: errors2,
|
|
187
186
|
touched: isTouched
|
|
188
187
|
},
|
|
189
188
|
{
|
|
190
|
-
ref:
|
|
189
|
+
ref: realErrors,
|
|
191
190
|
touched: true
|
|
192
191
|
}
|
|
193
192
|
].map((item) => {
|
|
@@ -204,6 +203,7 @@ function useFormChange({
|
|
|
204
203
|
});
|
|
205
204
|
return req;
|
|
206
205
|
});
|
|
206
|
+
if (requirements === void 0) return props;
|
|
207
207
|
return {
|
|
208
208
|
...props,
|
|
209
209
|
isInvalid: !ui.isValid,
|
|
@@ -241,7 +241,7 @@ function useFormChange({
|
|
|
241
241
|
),
|
|
242
242
|
hasInvalidValues: () => {
|
|
243
243
|
setTouched(allToValue(touched, true));
|
|
244
|
-
return JSON.stringify(
|
|
244
|
+
return JSON.stringify(realErrors.current).includes(":true");
|
|
245
245
|
},
|
|
246
246
|
touched,
|
|
247
247
|
resetForm: () => {
|
|
@@ -249,7 +249,9 @@ function useFormChange({
|
|
|
249
249
|
setTouched(val);
|
|
250
250
|
errors2.current = val;
|
|
251
251
|
setState(newState);
|
|
252
|
-
}
|
|
252
|
+
},
|
|
253
|
+
errors: errors2,
|
|
254
|
+
realErrors
|
|
253
255
|
};
|
|
254
256
|
}
|
|
255
257
|
export {
|