From 54bb143b84d5913705ef8d1cf9ad50676aa658c9 Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 24 Nov 2022 10:32:20 +0100 Subject: [PATCH 1/3] only set focus if the method exists --- src/components/Form.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Form.js b/src/components/Form.js index 74f3bbf12fed..f559ddbab653 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -258,7 +258,10 @@ class Form extends React.Component { onFixTheErrorsLinkPressed={() => { const errors = !_.isEmpty(this.state.errors) ? this.state.errors : this.props.formState.errorFields; const focusKey = _.find(_.keys(this.inputRefs), key => _.keys(errors).includes(key)); - this.inputRefs[focusKey].focus(); + const focusInput = this.inputRefs[focusKey]; + if (focusInput.focus && typeof(focusInput.focus === 'function')) { + focusInput.focus(); + } }} containerStyles={[styles.mh0, styles.mt5]} enabledWhenOffline={this.props.enabledWhenOffline} From f0de399723a7c8ecd93e8d83c1cd71d4b640160b Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 24 Nov 2022 12:51:55 +0100 Subject: [PATCH 2/3] back to the function approach --- src/components/Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Form.js b/src/components/Form.js index f559ddbab653..8544be678e3b 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -259,7 +259,7 @@ class Form extends React.Component { const errors = !_.isEmpty(this.state.errors) ? this.state.errors : this.props.formState.errorFields; const focusKey = _.find(_.keys(this.inputRefs), key => _.keys(errors).includes(key)); const focusInput = this.inputRefs[focusKey]; - if (focusInput.focus && typeof(focusInput.focus === 'function')) { + if (focusInput.focus && typeof(focusInput.focus) === 'function') { focusInput.focus(); } }} From edf41c4bdcffee359e30c6613994bf7ae8a8ecab Mon Sep 17 00:00:00 2001 From: Alberto Date: Thu, 24 Nov 2022 13:24:29 +0100 Subject: [PATCH 3/3] style --- src/components/Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Form.js b/src/components/Form.js index 8544be678e3b..ea0692ce1de9 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -259,7 +259,7 @@ class Form extends React.Component { const errors = !_.isEmpty(this.state.errors) ? this.state.errors : this.props.formState.errorFields; const focusKey = _.find(_.keys(this.inputRefs), key => _.keys(errors).includes(key)); const focusInput = this.inputRefs[focusKey]; - if (focusInput.focus && typeof(focusInput.focus) === 'function') { + if (focusInput.focus && typeof focusInput.focus === 'function') { focusInput.focus(); } }}