codeforlife 2.6.7 → 2.6.9
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
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.6.9](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.8...v2.6.9) (2025-02-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* rename property ([35827d7](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/35827d7452023f3a1ea8723b6b31fd9b84173cdd))
|
|
7
|
+
|
|
8
|
+
## [2.6.8](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.7...v2.6.8) (2025-02-24)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* form submission behavior ([#79](https://github.com/ocadotechnology/codeforlife-package-javascript/issues/79)) ([9b1ac2d](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/9b1ac2df0049cf473266798b6d210106045a86ee))
|
|
14
|
+
|
|
1
15
|
## [2.6.7](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.6...v2.6.7) (2025-02-19)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -56,14 +56,14 @@ type BaseFormProps<Values> = Omit<FormikConfig<Values>, "children"> & {
|
|
|
56
56
|
children: ReactNode | ((props: _FormikProps<Values>) => ReactNode)
|
|
57
57
|
scrollIntoViewOptions?: ScrollIntoViewOptions
|
|
58
58
|
nonFieldErrorsProps?: Omit<NonFieldErrorsProps, "children">
|
|
59
|
-
|
|
59
|
+
fieldRefs?: Array<{ name: string; inputRef: RefObject<HTMLInputElement> }>
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const BaseForm = <Values extends FormValues>({
|
|
63
63
|
children,
|
|
64
64
|
scrollIntoViewOptions = SCROLL_INTO_VIEW_OPTIONS,
|
|
65
65
|
nonFieldErrorsProps,
|
|
66
|
-
|
|
66
|
+
fieldRefs,
|
|
67
67
|
...otherFormikProps
|
|
68
68
|
}: BaseFormProps<Values>) => (
|
|
69
69
|
<Formik {...otherFormikProps}>
|
|
@@ -77,10 +77,12 @@ const BaseForm = <Values extends FormValues>({
|
|
|
77
77
|
{formik.errors.non_field_errors}
|
|
78
78
|
</NonFieldErrors>
|
|
79
79
|
)
|
|
80
|
-
}
|
|
80
|
+
}
|
|
81
|
+
// If a submission was attempted and refs to the fields were provided.
|
|
82
|
+
else if (formik.isSubmitting && fieldRefs && fieldRefs.length) {
|
|
81
83
|
const errorNames = getKeyPaths(formik.errors)
|
|
82
84
|
|
|
83
|
-
const inputRef =
|
|
85
|
+
const inputRef = fieldRefs.find(({ name }) =>
|
|
84
86
|
errorNames.includes(name),
|
|
85
87
|
)?.inputRef
|
|
86
88
|
|
|
@@ -32,7 +32,13 @@ const SubmitButton: FC<SubmitButtonProps> = ({
|
|
|
32
32
|
type="button"
|
|
33
33
|
onClick={() => {
|
|
34
34
|
form.setTouched(getTouched(form.values), true).then(errors => {
|
|
35
|
-
|
|
35
|
+
const hasErrors = Boolean(errors && Object.keys(errors).length)
|
|
36
|
+
// If has errors, set isSubmitting=true so fields in the form are
|
|
37
|
+
// aware that a submission was attempted. Else, set
|
|
38
|
+
// isSubmitting=false as it will be set to true when calling
|
|
39
|
+
// submitForm().
|
|
40
|
+
form.setSubmitting(hasErrors)
|
|
41
|
+
if (!hasErrors) form.submitForm()
|
|
36
42
|
})
|
|
37
43
|
}}
|
|
38
44
|
{...otherButtonProps}
|