Skip to content

Commit

Permalink
Fix bug preventing creation of collection tags
Browse files Browse the repository at this point in the history
Form would fail to submit when `collection` type was chosen and all fields filled.
The issue was the required subject tag body, which is only required for subject tags.
Inputs specific to a tag sub-type are now removed if that tag type is not selected.
  • Loading branch information
jimchamp committed Nov 27, 2024
1 parent e375806 commit e89d144
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions openlibrary/templates/type/tag/tag_form_inputs.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@
</div>
</div>

$if not type_picker_options.get("subjects_only", False):
$if type_picker_options.get("subjects_only", False):
<div class="sub-type-inputs">
<div class="sub-type-inputs__input-set hidden" data-input-type="subject">
<div class="sub-type-inputs__input-set" data-input-type="subject">
$:render_template("type/tag/subject/edit_form_inputs", page)
</div>
<div class="sub-type-inputs__input-set hidden" data-input-type="collection">
</div>
$else:
<div class="sub-type-inputs">
<div class="sub-type-inputs__input-set" data-input-type="subject">
$:render_template("type/tag/subject/edit_form_inputs", page)
</div>
<div class="sub-type-inputs__input-set" data-input-type="collection">
$:render_template("type/tag/collection/edit_form_inputs", page)
</div>
</div>
Expand All @@ -54,12 +60,22 @@
const SUBJECT_TYPES = ["subject", "person", "place", "time"]
const tagTypeSelector = document.querySelector('#tag_type')
const subTypeInputs = document.querySelectorAll(".sub-type-inputs__input-set")
const inputContainer = document.querySelector(".sub-type-inputs")
const inputSetMapping = {}

function initTagTypeSelector(selector) {
subTypeInputs.forEach((input) => {
inputSetMapping[input.dataset.inputType] = input
})
inputContainer.textContent = ""

if (selector.value) {
if (SUBJECT_TYPES.includes(selector.value)) {
showSubTypeInputs('subject')
} else {
showSubTypeInputs(selector.value)
}
}

selector.addEventListener("change", (event) => {
const selectedValue = event.target.value
Expand All @@ -78,13 +94,11 @@
}

function hideSubTypeInputs() {
subTypeInputs.forEach((input) => {
input.classList.add('hidden')
})
inputContainer.textContent = ""
}

function showSubTypeInputs(inputsToShow) {
inputSetMapping[inputsToShow].classList.remove('hidden')
inputContainer.appendChild(inputSetMapping[inputsToShow])
}

initTagTypeSelector(tagTypeSelector)
Expand Down

0 comments on commit e89d144

Please sign in to comment.