Alright, I think I'm doing that, but who knows. I've tried a hundred iterations and I'm basically just throwing spaghetti at the wall at this point, but nothing is sticking. I started reading the entire sheet workers wiki to see if there is some other issue not mentioned in the populateListOptions. The only thing I have seen is that I could change all my variables to all lowercase and remove all dashes. I think I have to leave the underscores in the repeating section attributes, but I can start removing every other dash and capital letter. My concern is that the issue is something else, something so simple, and I'm going to waste a lot of time changing names when that is not the culprit. If anyone has time and is interested to look this over, this is the Frankenstein's monster I have ended up with. It was built up in pieces and probably has wrong or unnecessary bits at this point, but it does correctly populate the <select> options from the fieldset. I just can't seem to get it to register a change when I select one of the options, or for any change to persist once the sheet is closed.
<select class="sheet-input dynamicWeaponSkillMenu" name="attr_dynamicWeaponSkillMenu"></select>
<script type="text/worker">
const updateDynamicWeaponSkillMenu = () => {
// First, retrieve the current saved value of attr_dynamicWeaponSkillMenu.
getAttrs(["attr_dynamicWeaponSkillMenu"], function(currentVals) {
const currentSelectValue = String(currentVals.attr_dynamicWeaponSkillMenu || "");
log("Current stored value: " + currentSelectValue);
// Get all the row IDs from the repeating_guncombatspec section.
getSectionIDs("repeating_guncombatspec", function(ids) {
let attrNames = [];
ids.forEach(id => {
attrNames.push("repeating_guncombatspec_" + id + "_skillSpeciality-GunCombatspec");
});
// Retrieve the attribute values for each row.
getAttrs(attrNames, function(values) {
let optionsArray = [];
ids.forEach(function(id) {
let specialityAttr = "repeating_guncombatspec_" + id + "_skillSpeciality-GunCombatspec";
let labelValue = values[specialityAttr] || "";
let optionObj = {
label: labelValue,
value: labelValue // using the name as both label and value
};
// If the stored value matches, mark this option as selected.
if (labelValue === currentSelectValue && currentSelectValue !== "") {
optionObj.selected = true;
}
optionsArray.push(optionObj);
});
log("Options Array: " + JSON.stringify(optionsArray));
// Populate the select element with the dynamically built options.
populateListOptions({
elemSelector: '.dynamicWeaponSkillMenu',
optionsArray: optionsArray,
overwrite: true,
callback: function() {
log("Dynamic Weapon Skill Menu options updated. Current value: " + currentSelectValue);
// Optionally, force persistence by resetting the attribute:
if (currentSelectValue !== "") {
setAttrs({ attr_dynamicWeaponSkillMenu: currentSelectValue }, function() {
log("attr_dynamicWeaponSkillMenu set to: " + currentSelectValue);
});
}
}
});
});
});
});
};
// Run the update function when the sheet is opened and when the repeating section changes.
on("sheet:opened", updateDynamicWeaponSkillMenu);
on("change:repeating_guncombatspec", updateDynamicWeaponSkillMenu);
// Try commenting out the change:attr_dynamicWeaponSkillMenu updater
// on("change:attr_dynamicWeaponSkillMenu", updateDynamicWeaponSkillMenu);
</script>
I wondered if I need, mandatory, to use a button to get the changes to stick, but my google-foo suggests not, unless it's a roll20-specific issue.
Again, I thank you (everyone) for your time and help and most importantly, patience.