-
-
Notifications
You must be signed in to change notification settings - Fork 583
feat (form-core): Merging Form-level server errors with Field-level errors #1432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
aecdb83
a9d48c9
fde9554
bea32b5
bc561fc
9d70231
9413ca6
7c22179
3c82c98
e86715e
c922835
d06c1ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,20 +96,41 @@ | |
| validationSource: 'form', | ||
| })) as UnwrapFormAsyncValidateOrFn<TOnServer> | undefined | ||
|
|
||
| console.log('ON SERVER ERROR', onServerError) | ||
|
|
||
| if (!onServerError) return values | ||
|
|
||
| const onServerErrorVal = ( | ||
| isGlobalFormValidationError(onServerError) | ||
| ? onServerError.form | ||
| : onServerError | ||
| ) as UnwrapFormAsyncValidateOrFn<TOnServer> | ||
| let onServerErrorVal = undefined | ||
| let onServerErrorValFields = undefined | ||
|
|
||
| if (isGlobalFormValidationError(onServerError)) { | ||
| onServerErrorVal = | ||
| onServerError.form as UnwrapFormAsyncValidateOrFn<TOnServer> | ||
| onServerErrorValFields = | ||
| onServerError.fields as UnwrapFormAsyncValidateOrFn<TOnServer> | ||
| } else { | ||
| onServerErrorVal = onServerError as UnwrapFormAsyncValidateOrFn<TOnServer> | ||
| } | ||
|
|
||
| // Extract string values from errors if they're in object format | ||
| const errorsArray = onServerErrorVal | ||
| ? Array.isArray(onServerErrorVal) | ||
| ? onServerErrorVal.map((err) => | ||
| typeof err === 'object' ? Object.values(err)[0] : err, | ||
|
||
| ) | ||
| : [ | ||
| typeof onServerErrorVal === 'object' | ||
| ? Object.values(onServerErrorVal)[0] | ||
| : onServerErrorVal, | ||
| ] | ||
| : [] | ||
|
||
|
|
||
| const formState: ServerFormState<TFormData, TOnServer> = { | ||
| errorMap: { | ||
| onServer: onServerError, | ||
| onServer: onServerErrorValFields, | ||
| }, | ||
| values, | ||
| errors: onServerErrorVal ? [onServerErrorVal] : [], | ||
| errors: errorsArray, | ||
| } | ||
|
|
||
| throw new ServerValidateError({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgotten
console.log