Fixed filter form data resetting when adding filter

This commit is contained in:
Risto Lahtela 2021-01-31 13:03:56 +02:00
parent 180547e078
commit 54b95c1c0a
3 changed files with 7 additions and 5 deletions

View File

@ -468,7 +468,7 @@
Highcharts.setOptions(Highcharts.theme);
updateGraphs();
} catch (e) {
if (graphs !== undefined) console.error(e);
console.error(e);
}
}

View File

@ -30,7 +30,7 @@ class MultipleChoiceFilter extends Filter {
<label for="${this.id}">${select}${this.label}:</label>
<button class="filter-remover btn btn-outline-secondary float-right"
onclick="removeFilter('${this.id}')"><i class="far fa-fw fa-trash-alt"></i></button>
<select class="form-control" multiple>`;
<select class="form-control" multiple style="margin-bottom: 0.5rem;">`;
for (const option of this.options.options) {
html += `<option>${option}</option>`;
@ -42,8 +42,8 @@ class MultipleChoiceFilter extends Filter {
toObject() {
let selected = [];
for (let option of document.querySelector(`#${this.id} select`).selectedOptions) {
selected.push(option.text);
for (let option of document.querySelector(`#${this.id} select`).options) {
if (option.selected) selected.push(option.text);
}
selected = JSON.stringify(selected);

View File

@ -101,7 +101,9 @@ function addFilter(parentSelector, filterIndex) {
const id = "f" + queryState.filterCount;
const filter = createFilter(loadedFilters[filterIndex], id);
queryState.filters.push(filter);
document.querySelector(parentSelector).innerHTML += filter.render(queryState.filterCount);
const inserting = document.createElement("template");
inserting.innerHTML = filter.render(queryState.filterCount);
document.querySelector(parentSelector).appendChild(inserting.content);
queryState.filterCount++;
}