@juantroconisf/lib 3.1.2 → 3.1.4
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -55,7 +55,7 @@ type GetValidationResponse = {
|
|
|
55
55
|
isValid: boolean;
|
|
56
56
|
validationProps: NextUIError;
|
|
57
57
|
};
|
|
58
|
-
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types
|
|
58
|
+
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types?: ValidatorParams, errorMessages?: ValidatorErrorMessage) => GetValidationResponse;
|
|
59
59
|
interface UseValidationFunc {
|
|
60
60
|
getValidation: GetValidationFunc<unknown>;
|
|
61
61
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ type GetValidationResponse = {
|
|
|
55
55
|
isValid: boolean;
|
|
56
56
|
validationProps: NextUIError;
|
|
57
57
|
};
|
|
58
|
-
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types
|
|
58
|
+
type GetValidationFunc<V extends unknown> = (value: V, isTouched: boolean, types?: ValidatorParams, errorMessages?: ValidatorErrorMessage) => GetValidationResponse;
|
|
59
59
|
interface UseValidationFunc {
|
|
60
60
|
getValidation: GetValidationFunc<unknown>;
|
|
61
61
|
}
|
package/dist/index.js
CHANGED
|
@@ -153,6 +153,7 @@ function useComponentLanguage() {
|
|
|
153
153
|
function useValidation() {
|
|
154
154
|
const { lang } = useComponentLanguage();
|
|
155
155
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
156
|
+
if (!types) return { isValid: true, validationProps: nxError() };
|
|
156
157
|
const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
|
|
157
158
|
if (value === "" && !isRequired || !isTouched)
|
|
158
159
|
return { isValid: true, validationProps: nxError() };
|
|
@@ -192,7 +193,7 @@ function useFormChange({
|
|
|
192
193
|
);
|
|
193
194
|
const registerHandle = (0, import_react.useCallback)(
|
|
194
195
|
(id) => {
|
|
195
|
-
const [value, isTouched] = [state[id], touched[id]], selectedValidations = validations[id], hasValidations = selectedValidations !== void 0, inputValidations = getValidation(
|
|
196
|
+
const [value, isTouched] = [state[id], touched[id]], selectedValidations = validations?.[id], hasValidations = selectedValidations !== void 0, inputValidations = getValidation(
|
|
196
197
|
value,
|
|
197
198
|
isTouched,
|
|
198
199
|
selectedValidations,
|
package/dist/index.mjs
CHANGED
|
@@ -134,6 +134,7 @@ function useComponentLanguage() {
|
|
|
134
134
|
function useValidation() {
|
|
135
135
|
const { lang } = useComponentLanguage();
|
|
136
136
|
const getValidation = (value, isTouched, types, errorMessages) => {
|
|
137
|
+
if (!types) return { isValid: true, validationProps: nxError() };
|
|
137
138
|
const items = Object.entries(types), requiredIndex = items.findIndex(([key]) => key === "required"), isRequired = requiredIndex === -1 ? false : items[requiredIndex][1];
|
|
138
139
|
if (value === "" && !isRequired || !isTouched)
|
|
139
140
|
return { isValid: true, validationProps: nxError() };
|
|
@@ -173,7 +174,7 @@ function useFormChange({
|
|
|
173
174
|
);
|
|
174
175
|
const registerHandle = useCallback(
|
|
175
176
|
(id) => {
|
|
176
|
-
const [value, isTouched] = [state[id], touched[id]], selectedValidations = validations[id], hasValidations = selectedValidations !== void 0, inputValidations = getValidation(
|
|
177
|
+
const [value, isTouched] = [state[id], touched[id]], selectedValidations = validations?.[id], hasValidations = selectedValidations !== void 0, inputValidations = getValidation(
|
|
177
178
|
value,
|
|
178
179
|
isTouched,
|
|
179
180
|
selectedValidations,
|