@juantroconisf/lib 2.3.4 → 2.3.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 +19 -16
- package/dist/index.mjs +20 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -192,22 +192,25 @@ function useFormChange(initialObj) {
|
|
|
192
192
|
setTouched(allToValue(initialObj, false));
|
|
193
193
|
setState(initialObj);
|
|
194
194
|
};
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
195
|
+
const register = (0, import_react.useCallback)(
|
|
196
|
+
(id, validations, errorMessages) => {
|
|
197
|
+
const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
198
|
+
errors2.current = handleNestedChange({
|
|
199
|
+
state: errors2.current,
|
|
200
|
+
id,
|
|
201
|
+
value: hasValidations ? !inputValidations.isValid : false
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
id,
|
|
205
|
+
onChange,
|
|
206
|
+
onBlur,
|
|
207
|
+
value,
|
|
208
|
+
isInvalid: hasValidations ? !inputValidations.isValid : false,
|
|
209
|
+
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
210
|
+
};
|
|
211
|
+
},
|
|
212
|
+
[getValidation, onChange, onBlur]
|
|
213
|
+
);
|
|
211
214
|
const hasInvalidValues = () => {
|
|
212
215
|
setTouched(allToValue(touched, true));
|
|
213
216
|
return JSON.stringify(errors2.current).includes(":true");
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/hooks/useFormChange.tsx
|
|
9
|
-
import { useState, useRef } from "react";
|
|
9
|
+
import { useState, useRef, useCallback } from "react";
|
|
10
10
|
|
|
11
11
|
// types/errors.ts
|
|
12
12
|
var NextUIError = class {
|
|
@@ -174,22 +174,25 @@ function useFormChange(initialObj) {
|
|
|
174
174
|
setTouched(allToValue(initialObj, false));
|
|
175
175
|
setState(initialObj);
|
|
176
176
|
};
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
177
|
+
const register = useCallback(
|
|
178
|
+
(id, validations, errorMessages) => {
|
|
179
|
+
const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
180
|
+
errors2.current = handleNestedChange({
|
|
181
|
+
state: errors2.current,
|
|
182
|
+
id,
|
|
183
|
+
value: hasValidations ? !inputValidations.isValid : false
|
|
184
|
+
});
|
|
185
|
+
return {
|
|
186
|
+
id,
|
|
187
|
+
onChange,
|
|
188
|
+
onBlur,
|
|
189
|
+
value,
|
|
190
|
+
isInvalid: hasValidations ? !inputValidations.isValid : false,
|
|
191
|
+
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
[getValidation, onChange, onBlur]
|
|
195
|
+
);
|
|
193
196
|
const hasInvalidValues = () => {
|
|
194
197
|
setTouched(allToValue(touched, true));
|
|
195
198
|
return JSON.stringify(errors2.current).includes(":true");
|