diff --git a/package.json b/package.json index 3b506ec..536b4a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@formkit/inertia", - "version": "0.1.5", + "version": "0.1.6", "description": "FormKit + Inertia = ❤️", "keywords": [ "formkit", diff --git a/src/addons/formkit.ts b/src/addons/formkit.ts index 9c4c4f3..f555ef4 100644 --- a/src/addons/formkit.ts +++ b/src/addons/formkit.ts @@ -30,14 +30,17 @@ export default (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) => {