Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/Form/FormProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function getInitialValueByType(valueType) {
}

function FormProvider({validate, formID, shouldValidateOnBlur, shouldValidateOnChange, children, formState, network, enabledWhenOffline, onSubmit, ...rest}) {
const inputRefs = useRef(null);
const inputRefs = useRef({});
const touchedInputs = useRef({});
const [inputValues, setInputValues] = useState({});
const [errors, setErrors] = useState({});
Expand Down Expand Up @@ -204,8 +204,10 @@ function FormProvider({validate, formID, shouldValidateOnBlur, shouldValidateOnC

const registerInput = useCallback(
(inputID, propsToParse = {}) => {
const newRef = propsToParse.ref || createRef();
inputRefs[inputID] = newRef;
const newRef = inputRefs.current[inputID] || propsToParse.ref || createRef();
if (inputRefs.current[inputID] !== newRef) {
inputRefs.current[inputID] = newRef;
}

if (!_.isUndefined(propsToParse.value)) {
inputValues[inputID] = propsToParse.value;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Form/FormWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function FormWrapper(props) {
footerContent={footerContent}
onFixTheErrorsLinkPressed={() => {
const errorFields = !_.isEmpty(errors) ? errors : formState.errorFields;
const focusKey = _.find(_.keys(inputRefs), (key) => _.keys(errorFields).includes(key));
const focusInput = inputRefs[focusKey].current;
const focusKey = _.find(_.keys(inputRefs.current), (key) => _.keys(errorFields).includes(key));
const focusInput = inputRefs.current[focusKey].current;

// Dismiss the keyboard for non-text fields by checking if the component has the isFocused method, as only TextInput has this method.
if (typeof focusInput.isFocused !== 'function') {
Expand Down
13 changes: 8 additions & 5 deletions src/pages/settings/Security/CloseAccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import * as CloseAccount from '../../../libs/actions/CloseAccount';
import ONYXKEYS from '../../../ONYXKEYS';
import Form from '../../../components/Form';
import CONST from '../../../CONST';
import ConfirmModal from '../../../components/ConfirmModal';
import * as ValidationUtils from '../../../libs/ValidationUtils';
import FormProvider from '../../../components/Form/FormProvider';
import InputWrapper from '../../../components/Form/InputWrapper';

const propTypes = {
/** Session of currently logged in user */
Expand Down Expand Up @@ -91,7 +92,7 @@ function CloseAccountPage(props) {
title={props.translate('closeAccountPage.closeAccount')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_SECURITY)}
/>
<Form
Comment thread
cdOut marked this conversation as resolved.
Resolved
<FormProvider
formID={ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM}
validate={validate}
onSubmit={showConfirmModal}
Expand All @@ -101,7 +102,8 @@ function CloseAccountPage(props) {
>
<View style={[styles.flexGrow1]}>
<Text>{props.translate('closeAccountPage.reasonForLeavingPrompt')}</Text>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="reasonForLeaving"
autoGrowHeight
textAlignVertical="top"
Expand All @@ -113,7 +115,8 @@ function CloseAccountPage(props) {
<Text style={[styles.mt5]}>
{props.translate('closeAccountPage.enterDefaultContactToConfirm')} <Text style={[styles.textStrong]}>{userEmailOrPhone}</Text>
</Text>
<TextInput
<InputWrapper
InputComponent={TextInput}
inputID="phoneOrEmail"
autoCapitalize="none"
label={props.translate('closeAccountPage.enterDefaultContact')}
Expand All @@ -136,7 +139,7 @@ function CloseAccountPage(props) {
shouldShowCancelButton
/>
</View>
</Form>
</FormProvider>
</ScreenWrapper>
);
}
Expand Down