fix: Update multiselect new skills

pull/1/head
Lunix-420 2024-11-14 19:18:29 +01:00
parent 859b91e5b7
commit e3dc6b63f5
1 changed files with 19 additions and 0 deletions

View File

@ -1,6 +1,25 @@
function handleSecondarySkillSelection(selectElement) {
const skillCreator = document.querySelector("#skillCreator");
const newSkillSelector = selectElement.closest(".row").cloneNode(true);
const selectedOptions = Array.from(
document.querySelectorAll("#skillCreator select[name='ssid']")
).map((select) => select.value);
// Filter out already selected options
const secondarySkillSelect =
newSkillSelector.querySelector("#secondarySkill");
const options = Array.from(secondarySkillSelect.options);
options.forEach((option) => {
if (selectedOptions.includes(option.value)) {
option.remove();
}
});
// Check if there are any options left to select
if (secondarySkillSelect.options.length <= 1) {
return; // Exit if no options left
}
newSkillSelector.querySelector("#secondarySkill").value = "";
newSkillSelector.querySelector("#level").value = "1";
newSkillSelector.querySelector(".btn-default").disabled = true;