Skip to content

Commit 8a84abc

Browse files
committed
validateForm method now returns form status.
1 parent 05568c2 commit 8a84abc

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

packages/lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "solid-form-handler",
33
"description": "A SolidJS library for simplifying form validations.",
4-
"version": "1.2.0-alpha.4",
4+
"version": "1.2.0-alpha.5",
55
"license": "MIT",
66
"type": "module",
77
"keywords": [

packages/lib/src/hooks/useFormHandler/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,19 @@ export const useFormHandler = <T = any>(validationSchema: ValidationSchema<T>, o
607607
setFormIsValidating(true);
608608
await validateField(
609609
ROOT_KEY,
610-
{ force: true, omitTriggers: true, throwException: true, ...options },
610+
{ force: true, omitTriggers: true, throwException: true, silentValidation: options?.silentValidation },
611611
{ ..._, recursive: true }
612612
);
613+
setFormIsValidating(false);
614+
return { isFormInvalid: false };
613615
} catch (error) {
614-
throw new FormErrorsException(error as ErrorMap);
615-
} finally {
616616
setFormIsValidating(false);
617+
618+
if (options?.throwException === false) {
619+
return { isFormInvalid: true };
620+
}
621+
622+
throw new FormErrorsException(error as ErrorMap);
617623
}
618624
};
619625

@@ -1081,7 +1087,7 @@ export const useFormHandler = <T = any>(validationSchema: ValidationSchema<T>, o
10811087
) => Promise<void>,
10821088
touchField,
10831089
validateField: validateField as (path?: string, options?: ValidateFieldOptions) => Promise<void>,
1084-
validateForm,
1090+
validateForm: validateForm as (options?: ValidateOptions) => Promise<{ isFormInvalid: boolean }>,
10851091
_: {
10861092
addFieldsetState,
10871093
buildFieldState,

0 commit comments

Comments
 (0)