Skip to content

Commit

Permalink
Merge pull request #37 from keitaroinc/keywords-fix
Browse files Browse the repository at this point in the history
Load all keyword options after category selection
  • Loading branch information
hristijankeitaro authored Nov 4, 2024
2 parents ea6cb10 + ca71429 commit 21fcd88
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<div style="margin:-20px 0px 20px 0px;">
<small><a href="javascript:void(0);" id="resetLink" onclick="resetKeywords()">Reset Keywords</a></small>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
var agroecologyKeyword = "{{ data.agroecology_keyword }}";
Expand Down Expand Up @@ -272,8 +271,15 @@
allowClear: true
});

function populateKeywords(category) {
var keywords = keywordOptions[category] || [];
function populateKeywords(categories) {
let keywords = [];

categories.forEach(function(category) {
keywords = keywords.concat(keywordOptions[category] || []);
});

keywords = [...new Set(keywords)];

$('#agroecology_keyword').empty();

keywords.forEach(function(keyword) {
Expand All @@ -288,17 +294,18 @@
}

categorySelect.addEventListener('change', function() {
var selectedCategory = categorySelect.value;
populateKeywords(selectedCategory);
const selectedCategories = Array.from(categorySelect.selectedOptions).map(option => option.value);
populateKeywords(selectedCategories);
});

var initialCategory = categorySelect.value;
if (initialCategory) {
populateKeywords(initialCategory);
const initialCategories = Array.from(categorySelect.selectedOptions).map(option => option.value);
if (initialCategories.length > 0) {
populateKeywords(initialCategories);
}
});

function resetKeywords() {
$('#agroecology_keyword').val(null).trigger('change');
}
</script>

0 comments on commit 21fcd88

Please sign in to comment.