File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -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 } ) =>
Original file line number Diff line number Diff line change @@ -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 }
You can’t perform that action at this time.
0 commit comments