diff --git a/src/fellchensammlung/static/fellchensammlung/js/custom.js b/src/fellchensammlung/static/fellchensammlung/js/custom.js new file mode 100644 index 0000000..e560a54 --- /dev/null +++ b/src/fellchensammlung/static/fellchensammlung/js/custom.js @@ -0,0 +1,8 @@ +function ifdef(variable, prefix = "", suffix = "") { + if (variable !== undefined) { + return prefix + variable + suffix; + } else { + return ""; + } + +} \ No newline at end of file diff --git a/src/fellchensammlung/templates/fellchensammlung/base_generic.html b/src/fellchensammlung/templates/fellchensammlung/base_generic.html index c11e564..524da80 100644 --- a/src/fellchensammlung/templates/fellchensammlung/base_generic.html +++ b/src/fellchensammlung/templates/fellchensammlung/base_generic.html @@ -14,6 +14,8 @@ + + diff --git a/src/fellchensammlung/templates/fellchensammlung/search.html b/src/fellchensammlung/templates/fellchensammlung/search.html index 22be51b..4c336d7 100644 --- a/src/fellchensammlung/templates/fellchensammlung/search.html +++ b/src/fellchensammlung/templates/fellchensammlung/search.html @@ -60,12 +60,12 @@ locations.forEach(location => { const listItem = document.createElement('li'); listItem.classList.add('result-item'); - listItem.textContent = location.properties.name + " (" + location.properties.city+")"; + listItem.textContent = location.properties.name + ifdef(location.properties.city, " (", ")"); // Add event when user clicks on a result location listItem.addEventListener('click', () => { - locationInput.value = location.properties.name + ", " + location.properties.city + ", " + location.properties.country; // Set input field to selected location + locationInput.value = location.properties.name +ifdef(location.properties.city, ", ", "") + ifdef(location.properties.country, ", ", ""); // Set input field to selected location resultsList.innerHTML = ''; // Clear the results after selecting a location });