Skip to content

Commit

Permalink
Merge pull request #2 from formkit/fix/form-level-error
Browse files Browse the repository at this point in the history
Fix/form level error
  • Loading branch information
fenilli authored May 27, 2024
2 parents ca55cb8 + 03ce3f9 commit adafac0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@formkit/inertia",
"version": "0.1.5",
"version": "0.1.6",
"description": "FormKit + Inertia = ❤️",
"keywords": [
"formkit",
Expand Down
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 adafac0

Please sign in to comment.