Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
29 deletions.
There are no files selected for viewing
58 changes: 29 additions & 29 deletions
58
import_export/static/import_export/export_selectable_fields.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
function hideUnselectedResourceFields(selectedResourceIndex) { | ||
const fields = document.querySelectorAll("[resource-index]") | ||
|
||
fields.forEach(field => { | ||
if (field.getAttribute("resource-index") !== selectedResourceIndex.toString()) { | ||
// field is wrapped by div, change visibility on wrapper | ||
field.style.display = "none" | ||
} | ||
}) | ||
const fields = document.querySelectorAll("[resource-index]"); | ||
|
||
fields.forEach((field) => { | ||
if (field.getAttribute("resource-index") !== selectedResourceIndex.toString()) { | ||
// field is wrapped by div, change visibility on wrapper | ||
field.style.display = "none"; | ||
} | ||
}); | ||
} | ||
|
||
function showSelectedResourceFields(resourceIndex) { | ||
const fields = document.querySelectorAll(`[resource-index="${resourceIndex}"]`) | ||
const fields = document.querySelectorAll(`[resource-index="${resourceIndex}"]`); | ||
|
||
fields.forEach(field => { | ||
// field is wrapped by div, change visibility on wrapper | ||
field.style.display = "block" | ||
}) | ||
fields.forEach((field) => { | ||
// field is wrapped by div, change visibility on wrapper | ||
field.style.display = "block"; | ||
}); | ||
} | ||
|
||
function onResourceSelected(e) { | ||
const resourceIndex = e.target.value | ||
const resourceIndex = e.target.value; | ||
|
||
showSelectedResourceFields(resourceIndex) | ||
showSelectedResourceFields(resourceIndex); | ||
|
||
hideUnselectedResourceFields(resourceIndex) | ||
hideUnselectedResourceFields(resourceIndex); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
const resourceSelector = document.querySelector("#id_resource") | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const resourceSelector = document.querySelector("#id_resource"); | ||
|
||
if (!resourceSelector) { | ||
console.error("resource select input not found") | ||
return | ||
} | ||
if (!resourceSelector) { | ||
console.error("resource select input not found"); | ||
return; | ||
} | ||
|
||
// If selector is actually select input, get selected option. | ||
// else selected resource index is 0 | ||
const selectedResourceIndex = resourceSelector.tagName === "SELECT" ? resourceSelector.value : 0 | ||
// If selector is actually select input, get selected option. | ||
// else selected resource index is 0 | ||
const selectedResourceIndex = resourceSelector.tagName === "SELECT" ? resourceSelector.value : 0; | ||
|
||
resourceSelector.addEventListener("input", onResourceSelected) | ||
resourceSelector.addEventListener("input", onResourceSelected); | ||
|
||
// initially hide unselected resource fields | ||
hideUnselectedResourceFields(selectedResourceIndex) | ||
}) | ||
// initially hide unselected resource fields | ||
hideUnselectedResourceFields(selectedResourceIndex); | ||
}); |