Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Prevent searching if country value is empty
Browse files Browse the repository at this point in the history
Simple defensive coding for now
  • Loading branch information
jbate committed Sep 15, 2015
1 parent 1dd0589 commit d910073
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<form>
<label for="country">Country</label>
<select name="country">
<option value="gbr">UK</option>
<option value="">Please select</option>
<option value="gbr" selected>UK</option>
<option value="usa">USA</option>
</select>

Expand Down
8 changes: 6 additions & 2 deletions src/js/contact-data-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ var contactDataServices = {
}
},
canSearch: function(){
// If search term is not empty and not the same as previous search term
return (contactDataServices.address.currentSearchTerm !== "" && contactDataServices.address.lastSearchTerm !== contactDataServices.address.currentSearchTerm);
// If search term is not empty and
return (contactDataServices.address.currentSearchTerm !== "" &&
// If search term is not the same as previous search term and
contactDataServices.address.lastSearchTerm !== contactDataServices.address.currentSearchTerm &&
// If the country is not empty
contactDataServices.address.countryList.value !== "");
},
// Bind a list of countries. Using either a user-defined list or creating a new one.
setCountryList: function(){
Expand Down

0 comments on commit d910073

Please sign in to comment.