codeforlife 2.6.9 → 2.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/components/form/Form.tsx +24 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.6.10](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.9...v2.6.10) (2025-02-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* non field errors ([dddf8d5](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/dddf8d5d1990c201ef72eff74b2d4f260ce4c7a4))
|
|
7
|
+
|
|
1
8
|
## [2.6.9](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.8...v2.6.9) (2025-02-25)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -45,7 +45,7 @@ const NonFieldErrors: FC<NonFieldErrorsProps> = ({
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export type FormErrors<Values> = FormikErrors<
|
|
48
|
-
Omit<Values, "
|
|
48
|
+
Omit<Values, "__all__"> & { __all__: string }
|
|
49
49
|
>
|
|
50
50
|
|
|
51
51
|
type _FormikProps<Values> = Omit<FormikProps<Values>, "errors"> & {
|
|
@@ -63,38 +63,38 @@ const BaseForm = <Values extends FormValues>({
|
|
|
63
63
|
children,
|
|
64
64
|
scrollIntoViewOptions = SCROLL_INTO_VIEW_OPTIONS,
|
|
65
65
|
nonFieldErrorsProps,
|
|
66
|
-
fieldRefs,
|
|
66
|
+
fieldRefs = [],
|
|
67
67
|
...otherFormikProps
|
|
68
68
|
}: BaseFormProps<Values>) => (
|
|
69
69
|
<Formik {...otherFormikProps}>
|
|
70
70
|
{/* @ts-expect-error */}
|
|
71
71
|
{(formik: _FormikProps<Values>) => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (inputRef?.current) {
|
|
90
|
-
inputRef.current.scrollIntoView(scrollIntoViewOptions)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
72
|
+
const hasErrors = Boolean(Object.keys(formik.errors).length)
|
|
73
|
+
const hasNonFieldErrors =
|
|
74
|
+
hasErrors && typeof formik.errors.__all__ === "string"
|
|
75
|
+
|
|
76
|
+
// If a submission was attempted and refs to the fields were provided.
|
|
77
|
+
if (
|
|
78
|
+
hasErrors &&
|
|
79
|
+
!hasNonFieldErrors &&
|
|
80
|
+
formik.isSubmitting &&
|
|
81
|
+
fieldRefs.length
|
|
82
|
+
) {
|
|
83
|
+
const errorNames = getKeyPaths(formik.errors)
|
|
84
|
+
|
|
85
|
+
const input = fieldRefs.find(({ name }) => errorNames.includes(name))
|
|
86
|
+
?.inputRef.current
|
|
87
|
+
|
|
88
|
+
if (input) input.scrollIntoView(scrollIntoViewOptions)
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
return (
|
|
96
92
|
<>
|
|
97
|
-
{
|
|
93
|
+
{hasNonFieldErrors && (
|
|
94
|
+
<NonFieldErrors {...nonFieldErrorsProps}>
|
|
95
|
+
{formik.errors.__all__ as string}
|
|
96
|
+
</NonFieldErrors>
|
|
97
|
+
)}
|
|
98
98
|
<FormikForm>
|
|
99
99
|
{typeof children === "function" ? children(formik) : children}
|
|
100
100
|
</FormikForm>
|