From a748524f27c418a0f8b69b304f3586ce5ae12173 Mon Sep 17 00:00:00 2001 From: Nicolas Hedger Date: Sat, 25 May 2024 17:18:08 +0200 Subject: [PATCH 1/4] fix: form-level error reporting --- src/addons/formkit.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/addons/formkit.ts b/src/addons/formkit.ts index 9c4c4f3..67036ed 100644 --- a/src/addons/formkit.ts +++ b/src/addons/formkit.ts @@ -28,16 +28,18 @@ export default (initialFields?: F, formLevelErrorName? }); on('error', (errors, node) => { - const _formLevelErrorName = formLevelErrorName ? formLevelErrorName : node.name; - - let formErrorMessages: string | undefined; - if (_formLevelErrorName in errors) { - formErrorMessages = errors[_formLevelErrorName]; - - delete errors[_formLevelErrorName]; + + /** + * 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 && formLevelErrorName in errors) { + formErrorMessages[0] = errors[formLevelErrorName]; + delete errors[formLevelErrorName]; } - node.setErrors(_formLevelErrorName, errors); + node.setErrors(formErrorMessages, errors); }); on('finish', (_, node) => { From 5c4ebdf2c6518d717c1ca7a9ae07255efb8d57cd Mon Sep 17 00:00:00 2001 From: Nicolas Hedger Date: Sat, 25 May 2024 17:22:56 +0200 Subject: [PATCH 2/4] formatting --- src/addons/formkit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addons/formkit.ts b/src/addons/formkit.ts index 67036ed..7556b46 100644 --- a/src/addons/formkit.ts +++ b/src/addons/formkit.ts @@ -32,7 +32,7 @@ export default (initialFields?: F, formLevelErrorName? /** * 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 && formLevelErrorName in errors) { formErrorMessages[0] = errors[formLevelErrorName]; From 4cac86a4a51d9473f148bce87e84f9d52099f8f3 Mon Sep 17 00:00:00 2001 From: Nicolas Hedger Date: Mon, 27 May 2024 13:28:25 +0200 Subject: [PATCH 3/4] apply suggestions --- src/addons/formkit.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/addons/formkit.ts b/src/addons/formkit.ts index 7556b46..f555ef4 100644 --- a/src/addons/formkit.ts +++ b/src/addons/formkit.ts @@ -28,15 +28,16 @@ export default (initialFields?: F, formLevelErrorName? }); on('error', (errors, node) => { - + const _formLevelErrorName = formLevelErrorName ? formLevelErrorName : node.name; + /** * 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 && formLevelErrorName in errors) { - formErrorMessages[0] = errors[formLevelErrorName]; - delete errors[formLevelErrorName]; + if (_formLevelErrorName in errors) { + formErrorMessages[0] = errors[_formLevelErrorName]; + delete errors[_formLevelErrorName]; } node.setErrors(formErrorMessages, errors); From e589b6426dff2379c7d1e6086bcf88db9230b24b Mon Sep 17 00:00:00 2001 From: Gustavo Fenilli Date: Mon, 27 May 2024 13:51:10 -0300 Subject: [PATCH 4/4] fix: error level forms Updates to 0.1.6 fixing form level errors being set as the name of the form, not the actual error. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",