async function showingitschoices(
choicesContainer,
selectedField,
selectedEventValue,
selectedFieldName,
buttonContainer,
container,
fieldNameContainer,
selectedChoices = null,
obj,
ruleIndex,
fieldIndex
) {
choicesContainer.innerHTML = '';
console.log("Existing Choices Values:", selectedChoices);
const choicesDropdown = document.createElement('fw-select');
choicesDropdown.classList.add('choices-dropdown');
choicesDropdown.setAttribute('label', ${selectedFieldName});
choicesDropdown.setAttribute('required', 'true');
choicesDropdown.setAttribute('placeholder', Choose ${selectedFieldName});
choicesDropdown.setAttribute('hint-text', 'Select multiple options');
choicesDropdown.setAttribute('multiple', 'true');
// // Map choices and pre-select based on selectedChoices
// selectedField.choices.forEach((choice) => {
// const option = document.createElement('fw-select-option');
// option.setAttribute('value', choice.id);
// option.textContent = choice.value;
// // // Check if this choice is in the selectedChoices array
// // if (selectedChoices && selectedChoices.includes(String(choice.id))) {
// // option.setAttribute('selected', 'true');
// // console.log(Existing value mapped: ${choice.value} (ID: ${choice.id}) for field: ${selectedFieldName});
// // }
// choicesDropdown.appendChild(option);
// });
console.log(Selected Field Name: ${selectedFieldName});
selectedField.choices.forEach((choice) => {
console.log(Processing choice: ${choice.value} (ID: ${choice.id}));
const option = document.createElement('fw-select-option');
option.setAttribute('value', choice.id);
option.textContent = choice.value;
if (selectedChoices && selectedChoices.includes(String(choice.id))) {
option.setAttribute('selected', 'selected');
}
choicesDropdown.appendChild(option);
console.log(Option appended to dropdown.);
});
// console.log(--- Dropdown Creation Completed ---);
// console.log(Dropdown HTML:, choicesDropdown.outerHTML);
choicesContainer.appendChild(choicesDropdown);
console.log(Dropdown added to choicesContainer.);
choicesContainer.appendChild(choicesDropdown);
// Event listener for fwChange to update JSON with selected choices
choicesDropdown.addEventListener('fwChange', (event) => {
const selectedChoiceIds = Array.isArray(event.target.value) ? event.target.value : [event.target.value];
const findRule = ticketworkflowconditions[ruleIndex];
const combination = findRule.event.combination;
const newKeyValue = { [selectedFieldName]: selectedChoiceIds.length ? selectedChoiceIds : null };
combination.splice(fieldIndex, 1, newKeyValue);
console.log(`Updated JSON with field: ${selectedFieldName}, choices: ${selectedChoiceIds}`);
console.log(`Updated ticketworkflowconditions: ${JSON.stringify(ticketworkflowconditions, null, 2)}`);
});
}
understand selectedchoices has a value as array like
[
"3",
"1",
"2"
]
based on this value why it is not mapping to the dropdown