Skip to content

Commit

Permalink
fix(Autocomplete): Fix potential race condition
Browse files Browse the repository at this point in the history
It's possible that interface has not yet been initialised while it's
reaching out to the API
  • Loading branch information
cblanc committed Mar 31, 2020
1 parent 256f5da commit 8a5b66d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions view/base/web/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@
);
self._postcodeLookupInstances.push($instance);
self.detectCountry(); // Check if correct country is engaged

},
onAddressSelected: self.handleAddressSelection.bind(self),
onSearchError: self.handleError.bind(self)
Expand All @@ -259,6 +258,7 @@
IdpcBinding.prototype.hideAll = function() {
this._autocompleteInstances.forEach(function(instance) {
var interface = instance.interface;
if (!interface) return;
var input = interface.input;

// Disable current autocomplet activity just in case
Expand All @@ -283,7 +283,8 @@

IdpcBinding.prototype.showAll = function() {
this._autocompleteInstances.forEach(function(instance) {
instance.interface.initialiseEventListeners();
var interface = instance.interface;
if (interface) interface.initialiseEventListeners();
});
this._postcodeLookupInstances.forEach(function($instance) {
$instance.show();
Expand Down

0 comments on commit 8a5b66d

Please sign in to comment.