File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
Expand file tree Collapse file tree 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>({
7777 { formik . errors . non_field_errors }
7878 </ NonFieldErrors >
7979 )
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 ) {
8183 const errorNames = getKeyPaths ( formik . errors )
8284
8385 const inputRef = order . find ( ( { name } ) =>
Original file line number Diff line number Diff line change @@ -32,7 +32,13 @@ const SubmitButton: FC<SubmitButtonProps> = ({
3232 type = "button"
3333 onClick = { ( ) => {
3434 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 ( )
3642 } )
3743 } }
3844 { ...otherButtonProps }
You can’t perform that action at this time.
0 commit comments