|
|
@ -16,12 +16,32 @@ const useFormUtils = < |
|
|
|
): FormUtils<M> => { |
|
|
|
): FormUtils<M> => { |
|
|
|
const [formValidity, setFormValidity] = useState<FormValidity<M>>({}); |
|
|
|
const [formValidity, setFormValidity] = useState<FormValidity<M>>({}); |
|
|
|
|
|
|
|
|
|
|
|
const setValidity = useCallback((key: keyof M, value: boolean) => { |
|
|
|
const setValidity = useCallback((key: keyof M, value?: boolean) => { |
|
|
|
setFormValidity( |
|
|
|
setFormValidity( |
|
|
|
buildObjectStateSetterCallback<FormValidity<M>>(key, value), |
|
|
|
buildObjectStateSetterCallback<FormValidity<M>>(key, value), |
|
|
|
); |
|
|
|
); |
|
|
|
}, []); |
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const setValidityRe = useCallback((re: RegExp, value?: boolean) => { |
|
|
|
|
|
|
|
setFormValidity((previous) => { |
|
|
|
|
|
|
|
const result: FormValidity<M> = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(previous).forEach((key) => { |
|
|
|
|
|
|
|
const id = key as keyof M; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (re.test(key)) { |
|
|
|
|
|
|
|
if (value !== undefined) { |
|
|
|
|
|
|
|
result[id] = value; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
result[id] = previous[id]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
const buildFinishInputTestBatchFunction = useCallback( |
|
|
|
const buildFinishInputTestBatchFunction = useCallback( |
|
|
|
(key: keyof M) => (result: boolean) => { |
|
|
|
(key: keyof M) => (result: boolean) => { |
|
|
|
setValidity(key, result); |
|
|
|
setValidity(key, result); |
|
|
@ -66,6 +86,7 @@ const useFormUtils = < |
|
|
|
setFormValidity, |
|
|
|
setFormValidity, |
|
|
|
setMsgSetter, |
|
|
|
setMsgSetter, |
|
|
|
setValidity, |
|
|
|
setValidity, |
|
|
|
|
|
|
|
setValidityRe, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|