Skip to content
5 changes: 5 additions & 0 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ class Form extends React.Component {
this.state.inputValues[inputID] = defaultValue;
}

// We force the form to set the input value from the defaultValue props if there is a saved valid value
if (child.props.shouldUseDefaultValue) {
this.state.inputValues[inputID] = child.props.defaultValue;
}

if (!_.isUndefined(child.props.value)) {
this.state.inputValues[inputID] = child.props.value;
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/TextInput/baseTextInputPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const propTypes = {

/** Indicate whether pressing Enter on multiline input is allowed to submit the form. */
submitOnEnter: PropTypes.bool,

/** Set the default value to the input if there is a valid saved value */
shouldUseDefaultValue: PropTypes.bool,
};

const defaultProps = {
Expand Down Expand Up @@ -109,6 +112,7 @@ const defaultProps = {
shouldDelayFocus: false,
submitOnEnter: false,
icon: null,
shouldUseDefaultValue: false,
};

export {propTypes, defaultProps};
20 changes: 0 additions & 20 deletions src/libs/ReimbursementAccountUtils.js

This file was deleted.

2 changes: 2 additions & 0 deletions src/pages/ReimbursementAccount/BankAccountManualStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class BankAccountManualStep extends React.Component {
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
disabled={shouldDisableInputs}
shouldSaveDraft
shouldUseDefaultValue={shouldDisableInputs}
/>
<TextInput
inputID="accountNumber"
Expand All @@ -110,6 +111,7 @@ class BankAccountManualStep extends React.Component {
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
disabled={shouldDisableInputs}
shouldSaveDraft
shouldUseDefaultValue={shouldDisableInputs}
/>
<CheckboxWithLabel
style={styles.mt4}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/ReimbursementAccount/CompanyStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class CompanyStep extends React.Component {
disabled={shouldDisableCompanyName}
defaultValue={this.props.getDefaultStateForField('companyName')}
shouldSaveDraft
shouldUseDefaultValue={shouldDisableCompanyName}
/>
<AddressForm
translate={this.props.translate}
Expand Down Expand Up @@ -209,6 +210,7 @@ class CompanyStep extends React.Component {
placeholder={this.props.translate('companyStep.taxIDNumberPlaceholder')}
defaultValue={this.props.getDefaultStateForField('companyTaxID')}
shouldSaveDraft
shouldUseDefaultValue={shouldDisableCompanyTaxID}
/>
<View style={styles.mt4}>
<Picker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import ROUTES from '../../ROUTES';
import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
import * as ReimbursementAccountProps from './reimbursementAccountPropTypes';
import reimbursementAccountDraftPropTypes from './ReimbursementAccountDraftPropTypes';
import * as ReimbursementAccountUtils from '../../libs/ReimbursementAccountUtils';
import withPolicy from '../workspace/withPolicy';

const propTypes = {
Expand Down Expand Up @@ -125,7 +124,7 @@ class ReimbursementAccountPage extends React.Component {
* @returns {*}
*/
getDefaultStateForField(fieldName, defaultValue = '') {
return ReimbursementAccountUtils.getDefaultStateForField(this.props.reimbursementAccountDraft, this.props.reimbursementAccount, fieldName, defaultValue);
return lodashGet(this.props.reimbursementAccount, ['achData', fieldName], defaultValue);
Comment on lines 126 to +127

@Santhosh-Sellavel Santhosh-Sellavel May 11, 2023

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change led to regression. We should prefer to draft, that got deleted, more details here

}

/**
Expand Down