The title is somewhat vague, and I apologize for that! Once again, as a disclaimer, I am highly inexperienced, and any code I provide is likely to be very inefficient. So I'm working with a test sheet for another sheet I'm working on. The intention was to have an Inventory page with a Repeating Section where the players add weapons they acquire. They also have a Combat Section with 3 static weapon slots, representing the Weapons they have readily accessable. So I put together a sheet worker ( I cannot express enough how much of this is just cannabalized from other Sheet Workers I've found, I'm still far from fluent in JS, let alone JS as it's used in Sheet Workers). It detects a change in a Dropdown (options: Slot 1, Slot 2, Slot 3), that when selected will fill in the corresponding fields in the Combat section. The issue I have run into is that it does update the corresponding fields, but requires the page to be refreshed, or for the Character Sheet to be closed and opened to reflect the changes. For the life of me I can't figure out what I'm missing to have it update in real time. Here is my html: <div class="combat">
<div class="weapon_stats" id="weapon_slot1">
<h3>Weapon Slot 1</h3>
Weapon Name:
<input type="text" name="attr_weapon1_name" readonly style="background: transparent; border: none;">
Damage Type:
<input type="text" name="attr_weapon1_damage_type" readonly style="background: transparent; border: none;">
Damage:
<input type="text" name="attr_weapon1_damage" readonly style="background: transparent; border: none;">
</div>
<div class="weapon_stats" id="weapon_slot2">
<h3>Weapon Slot 2</h3>
Weapon Name:
<input type="text" name="attr_weapon2_name" readonly style="background: transparent; border: none;">
Damage Type:
<input type="text" name="attr_weapon2_damage_type" readonly style="background: transparent; border: none;">
Damage:
<input type="text" name="attr_weapon2_damage" readonly style="background: transparent; border: none;">
</div>
<div class="weapon_stats" id="weapon_slot3">
<h3>Weapon Slot 3</h3>
Weapon Name:
<input type="text" name="attr_weapon3_name" readonly style="background: transparent; border: none;">
Damage Type:
<input type="text" name="attr_weapon3_damage_type" readonly style="background: transparent; border: none;">
Damage:
<input type="text" name="attr_weapon3_damage" readonly style="background: transparent; border: none;">
</div>
</div>
<div class="inventory">
<fieldset class="repeating_weapons">
<div class="weapon_entry">
<span class="stat-label">Weapon Name:</span>
<input class="input" name="attr_weapon_name" type="text" placeholder="Enter Weapon Name"/>
<span class="stat-label">Damage Type:</span>
<input class="input" name="attr_damage_type" type="text" placeholder="Enter Damage Type"/>
<span class="stat-label">Damage:</span>
<input class="input" name="attr_damage" type="text" placeholder="Enter Damage"/>
<span class="stat-label">Assign to Slot:</span>
<select class="select" name="attr_weapon_slot">
<option value="">Select Slot</option>
<option value="slot1">Slot 1</option>
<option value="slot2">Slot 2</option>
<option value="slot3">Slot 3</option>
</select>
</div>
</fieldset>
</div> and the Sheet Worker <script type="text/worker">
on('change:repeating_weapons:weapon_slot', function() {
getSectionIDs('repeating_weapons', function(IDArray) {
var fieldNames = IDArray.flatMap(id => [
`repeating_weapons_${id}_weapon_name`,
`repeating_weapons_${id}_damage_type`,
`repeating_weapons_${id}_damage`,
`repeating_weapons_${id}_weapon_slot`
]);
getAttrs(fieldNames, function(values) {
var updates = {
'weapon1_name': '',
'weapon1_damage_type': '',
'weapon1_damage': '',
'weapon2_name': '',
'weapon2_damage_type': '',
'weapon2_damage': '',
'weapon3_name': '',
'weapon3_damage_type': '',
'weapon3_damage': ''
};
IDArray.forEach(id => {
var base = `repeating_weapons_${id}`;
var slot = values[`${base}_weapon_slot`];
if (slot && slot.startsWith('slot')) {
var slotNumber = slot.replace('slot', '');
updates[`weapon${slotNumber}_name`] = values[`${base}_weapon_name`];
updates[`weapon${slotNumber}_damage_type`] = values[`${base}_damage_type`];
updates[`weapon${slotNumber}_damage`] = values[`${base}_damage`];
}
});
setAttrs(updates, function() {
console.log("Combat section updated successfully based on weapon slots:", updates);
});
});
});
});
</script>
Again, it otherwise works as intended, but the update only occurs upon a page refresh, or by closing and opening the character sheet.