codeforlife 2.6.7 → 2.6.8

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,10 @@
1
+ ## [2.6.8](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.7...v2.6.8) (2025-02-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * form submission behavior ([#79](https://github.com/ocadotechnology/codeforlife-package-javascript/issues/79)) ([9b1ac2d](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/9b1ac2df0049cf473266798b6d210106045a86ee))
7
+
1
8
  ## [2.6.7](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.6...v2.6.7) (2025-02-19)
2
9
 
3
10
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "codeforlife",
3
3
  "description": "Common frontend code",
4
4
  "private": false,
5
- "version": "2.6.7",
5
+ "version": "2.6.8",
6
6
  "type": "module",
7
7
  "scripts": {
8
8
  "dev": "vite",
@@ -77,7 +77,9 @@ const BaseForm = <Values extends FormValues>({
77
77
  {formik.errors.non_field_errors}
78
78
  </NonFieldErrors>
79
79
  )
80
- } else if (order && order.length) {
80
+ }
81
+ // If a submission was attempted and refs to the fields were provided.
82
+ else if (formik.isSubmitting && order && order.length) {
81
83
  const errorNames = getKeyPaths(formik.errors)
82
84
 
83
85
  const inputRef = order.find(({ name }) =>
@@ -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
- if (!errors || !Object.keys(errors).length) form.submitForm()
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}