
Hi, I have a problem with a function from the repeatingSum page on the wiki. I am trying to replicate the conditional example for it. I have a field for the weight in the repeating section as well as a checkbox. I want to have a field outside the repeating section that tallies up the total weight only for the rows where the checkbox is marked. The example on the wiki is: on ( 'change:repeating_armour remove:repeating_armour' , function () {
repeatingSum ( "armour_weight" , "armour" ,[ "armour_piece" ,"armour_worn"]);
});
And here is the HTML from my test: <input type="text" class="sheet-input" name="attr_geartotalcarriedtest"/>
<input type="text" class="sheet-input" name="attr_geartotalweighttest"/>
<div>
<fieldset class="repeating_othergear">
<div>
<table class="sheet-skill" style="width:800px">
<tr>
<th><input type="checkbox" class="sheet-carried" name="attr_gearequipped" value="0"/><span></span></th>
<th data-i18n="gearcell-u"style="width:50px;">Gear</th>
<th><input type="text" class="sheet-input" style="width:140px" name="attr_gearnamerep" /></th>
<th data-i18n="gearquantity-u" style="width:50px;">Quantity</th>
<th><input type="text" class="sheet-input"style="width:40px;" name="attr_gearquantityrep" value="0" /></th>
<th data-i18n="gearweight-u"style="width:50px;">KG each</th>
<th><input type="text" class="sheet-input" style="width:50px;" name="attr_gearmasseachrep" value="0" step="0.05"/></th>
<th data-i18n="gearweightplusquantity-u"style="width:50px;">Weight</th>
<th><input type="text" class="sheet-input" style="width:40px;" name="attr_gearmasstotalrep" value="0" step="0.05"/></th>
<th><input class="sheet-textbox" type="text" style="width:290px; margin-left:5px;" value="" name="attr_gearnoterep" placeholder="Info" /></th>
</tr>
</table>
</div>
</fieldset>
</div>
<script type="text/worker">
const repeatingSum = (destinations, section, fields) => {
if (!Array.isArray(destinations)) destinations = [destinations.replace(/\s/g, '').split(',')];
if (!Array.isArray(fields)) fields = [fields.replace(/\s/g, '').split(',')];
getSectionIDs(`repeating_${section}`, idArray => {
const attrArray = idArray.reduce((m, id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))], []);
getAttrs([...attrArray], v => {
const getValue = (section, id, field) => v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : parseFloat(v[`repeating_${section}_${id}_${field}`]) || 0;
const commonMultipliers = (fields.length <= destinations.length) ? [] : fields.splice(destinations.length, fields.length - destinations.length);
const output = {};
destinations.forEach((destination, index) => {
output[destination] = idArray.reduce((total, id) => total + getValue(section, id, fields[index]) * commonMultipliers.reduce((subtotal, mult) => subtotal * getValue(section, id, mult), 1), 0);
});
setAttrs(output);
});
});
};
on('change:repeating_othergear remove:repeating_othergear', function() {
repeatingSum("geartotalcarriedtest","othergear",["gearmasstotalrep", "gearequipped"]);
});
on('change:repeating_othergear remove:repeating_othergear', function() {
repeatingSum("geartotalweighttest","othergear","gearmasstotalrep");
});
</script>
The field (geartotalcarriedtest) that the total of the checked rows should be totalled gets set to 0 and it sets all checkboxes to marked. Not sure what is different from the example to what I put in there. What should I change to get it work?