Skip to content

Commit

Permalink
Merge pull request #221 from vtex/fix/autocomplete-api
Browse files Browse the repository at this point in the history
Fixes Postal Code autocomplete which should only call API if country is supported
  • Loading branch information
omninando authored Nov 27, 2019
2 parents 5f3934a + 7e32e25 commit 821b419
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Postal Code autocomplete which should only call API if country is supported

## [3.8.3] - 2019-11-27

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion react/AddressContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ class AddressContainer extends Component {
changedAddressFields.postalCode &&
!changedAddressFields.postalCode.geolocationAutoCompleted
) {
const postalCodeField = rules.fields.find(
field => field.name === 'postalCode',
)
const diffFromPrev =
address.postalCode.value !== validatedAddress.postalCode.value
const isValidPostalCode = validatedAddress.postalCode.valid === true
const shouldAutoComplete =
rules.postalCodeFrom === POSTAL_CODE &&
diffFromPrev &&
isValidPostalCode
isValidPostalCode &&
postalCodeField.postalCodeAPI

if (shouldAutoComplete) {
return onChangeAddress(
Expand Down
1 change: 1 addition & 0 deletions react/country/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
label: 'postalCode',
size: 'small',
autoComplete: 'nope',
postalCodeAPI: false,
},
{
name: 'street',
Expand Down

0 comments on commit 821b419

Please sign in to comment.