diff --git a/src/components/AddressSearch.js b/src/components/AddressSearch.js index 9d3cacceca6d1..e2cbe6901076e 100644 --- a/src/components/AddressSearch.js +++ b/src/components/AddressSearch.js @@ -66,8 +66,11 @@ const AddressSearch = (props) => { const state = GooglePlacesUtils.getAddressComponent(addressComponents, 'administrative_area_level_1', 'short_name'); const values = {}; - if (street && street.length > props.value.length) { - // Don't replace if the user has typed something longer. I.e. maybe the user entered the Apt # + if (street && street.length > props.value.trim().length) { + // We are only passing the street number and name if the combined length is longer than the value + // that was initially passed to the autocomplete component. Google Places can truncate details + // like Apt # and this is the best way we have to tell that the new value it's giving us is less + // specific than the one the user entered manually. values.street = street; } if (city) { diff --git a/src/pages/ReimbursementAccount/CompanyStep.js b/src/pages/ReimbursementAccount/CompanyStep.js index 14379652b4f72..358462dca5eac 100644 --- a/src/pages/ReimbursementAccount/CompanyStep.js +++ b/src/pages/ReimbursementAccount/CompanyStep.js @@ -87,14 +87,6 @@ class CompanyStep extends React.Component { hasNoConnectionToCannabis: 'bankAccount.error.restrictedBusiness', }; - // AddressSearch uses different keys for these fields - this.renamedFields = { - street: 'addressStreet', - state: 'addressState', - city: 'addressCity', - zipCode: 'addressZipCode', - }; - this.getErrorText = inputKey => ReimbursementAccountUtils.getErrorText(this.props, this.errorTranslationKeys, inputKey); this.clearError = inputKey => ReimbursementAccountUtils.clearError(this.props, inputKey); this.clearErrors = inputKeys => ReimbursementAccountUtils.clearErrors(this.props, inputKeys); @@ -226,9 +218,15 @@ class CompanyStep extends React.Component { state: this.getErrors().addressState, }} onFieldChange={(values) => { + const renamedFields = { + street: 'addressStreet', + state: 'addressState', + city: 'addressCity', + zipCode: 'addressZipCode', + }; const renamedValues = {}; _.each(values, (value, inputKey) => { - const renamedInputKey = lodashGet(this.renamedFields, inputKey, inputKey); + const renamedInputKey = lodashGet(renamedFields, inputKey, inputKey); renamedValues[renamedInputKey] = value; }); this.setValue(renamedValues);