Skip to content

Commit

Permalink
Merge pull request #1 from nhedger/form-error
Browse files Browse the repository at this point in the history
fix: form-level error reporting
  • Loading branch information
fenilli authored May 27, 2024
2 parents e589b64 + 4cac86a commit 03ce3f9
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/addons/formkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ export default <F extends RequestPayload>(initialFields?: F, formLevelErrorName?
on('error', (errors, node) => {
const _formLevelErrorName = formLevelErrorName ? formLevelErrorName : node.name;

let formErrorMessages: string | undefined;
/**
* If one of the errors should be displayed at the form level, we extract
* it from the errors object and set it as a form level error.
*/
const formErrorMessages: string[] = [];
if (_formLevelErrorName in errors) {
formErrorMessages = errors[_formLevelErrorName];

formErrorMessages[0] = errors[_formLevelErrorName];
delete errors[_formLevelErrorName];
}

node.setErrors(_formLevelErrorName, errors);
node.setErrors(formErrorMessages, errors);
});

on('finish', (_, node) => {
Expand Down

0 comments on commit 03ce3f9

Please sign in to comment.