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

Commit

Permalink
fix(administrative): the administrative can be undefined (#99)
Browse files Browse the repository at this point in the history
Also, do not use the `administrative` if it has the same value than
`name`.
  • Loading branch information
redox committed Apr 11, 2016
1 parent d9d47e5 commit ace575d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/createHitFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import findCountryCode from './findCountryCode.js';
export default function createHitFormatter({formatAutocompleteSuggestion, formatInputValue}) {
return hit => {
try {
const administrative = hit.administrative && hit.administrative[0] !== hit.locale_names[0] ?
hit.administrative[0] : undefined;
let suggestion = {
administrative: hit.administrative && hit.administrative[0],
administrative,
city: hit.city && hit.city[0],
country: hit.country,
countryCode: findCountryCode(hit._tags),
Expand Down
4 changes: 2 additions & 2 deletions src/formatAutocompleteSuggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function formatAutocompleteSuggestion({
}) {
const out = `<span class="ap-suggestion-icon">${isCity === true ? cityIcon : addressIcon}</span>
<span class="ap-name">${name}</span> <span class="ap-address">
${isCity === false ? `${city},` : ``}
${administrative},
${isCity === false ? `${city},` : ''}
${administrative ? `${administrative},` : ''}
${country}</span>`
.replace(/\n/g, '');

Expand Down
2 changes: 1 addition & 1 deletion src/formatInputValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function formatInputValue({
}) {
const out = `${name}
${isCity === false ? ` ${city},` : ''}
${administrative},
${administrative ? `${administrative},` : ''}
${country}`
.replace(/\n/g, '');

Expand Down

0 comments on commit ace575d

Please sign in to comment.