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

Commit

Permalink
Change country to countryList and use a method to set it
Browse files Browse the repository at this point in the history
And add a placeholder for creating a new dropdown list if the user
hasn't supplied us with one...
  • Loading branch information
jbate committed Sep 15, 2015
1 parent a588c5e commit 1dd0589
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
address: {
elements: {
input: document.querySelector("input[name='address-input']"),
country: document.querySelector("select"),
countryList: document.querySelector("select"),
picklist: document.querySelector("#picklist"),
formattedAddress: document.querySelector("#formatted-address")
}
Expand Down
20 changes: 17 additions & 3 deletions src/js/contact-data-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ var contactDataServices = {
if(!contactDataServices.token){
console.log("Please provide a token for ContactDataServices.");
}

contactDataServices.address.setCountryList();
contactDataServices.address.input = contactDataServices.address.elements.input;
contactDataServices.address.input.addEventListener("keyup", contactDataServices.address.search);
contactDataServices.address.country = contactDataServices.address.elements.country;
contactDataServices.address.input.addEventListener("keyup", contactDataServices.address.search);
},
address: {
input: null,
Expand All @@ -60,7 +61,7 @@ var contactDataServices = {
search: function(){
console.log(contactDataServices.address.input.value);
contactDataServices.address.currentSearchTerm = contactDataServices.address.input.value,
contactDataServices.address.currentCountryCode = contactDataServices.address.country.value;
contactDataServices.address.currentCountryCode = contactDataServices.address.countryList.value;

// Check is searching is permitted
if(contactDataServices.address.canSearch()){
Expand Down Expand Up @@ -92,6 +93,19 @@ var contactDataServices = {
// If search term is not empty and not the same as previous search term
return (contactDataServices.address.currentSearchTerm !== "" && contactDataServices.address.lastSearchTerm !== contactDataServices.address.currentSearchTerm);
},
// Bind a list of countries. Using either a user-defined list or creating a new one.
setCountryList: function(){
contactDataServices.address.countryList = contactDataServices.address.elements.countryList;

// If the user hasn't passed us a country list, then create new list
if(!contactDataServices.address.countryList){
contactDataServices.address.createCountryDropdown();
}
},
createCountryDropdown: function(){
// What countries?
// Where to position it?
},
// Get a final (Formatted) address
format: function(url){
contactDataServices.address.currentFormatUrl = contactDataServices.urls.construct.address.format(url);
Expand Down

0 comments on commit 1dd0589

Please sign in to comment.