
I have a sheet worker to build a list of skills (skills can be renamed and that's why I use a sheet worker to "build" the names) in a repeating section. The problem, TypeError: t is undefined (in Firefox) or Uncaught TypeError: Cannot read property 'toString' of undefined (in Chrome), only occurs the first time the sheet worker is triggered. Subsequent times, no issue. The issue occurs at the same spot every time (it builds the list properly until it hits the spell casting skill). I have a drop down in this repeating section that controls the button to either roll the relevant skill for the spell/power, roll damage only for the spell/power, or roll both the skill and the damage. The default is Damage only. If I change that drop down to Skill Only, or Atk+Damage, the skill list displays, but Spellcasting and Weird Science are blank (i.e. no label to know what I'm picking). If I then select the other option (Atk+Damage or Skill Only, whichever I didn't choose the first time), the sheet worker triggers with no exception and the skill list is fully populated. I can then swap back and forth between the two with no issues. This same stuff is used for the Weapons repeating section and has no issues at all. It is always Spellcasting where it dies. Any help in identifying why this is happening would be appreciated. Here's the relevant code snippets: HTML+Sheet Worker : <!--Athletics--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="athletics">Athletics</label> = <input type="text" class="sheet-csnInput" name="attr_athleticsname" value="" /></div>
<!--Faith--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="faith">Faith</label> = <input type="text" class="sheet-csnInput" name="attr_faithname" value="" /></div>
<!--Focus--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="focus">Focus</label> = <input type="text" class="sheet-csnInput" name="attr_focusname" value="" /></div>
<!--Performance--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="performance">Performance</label> = <input type="text" class="sheet-csnInput" name="attr_performancename" value="" /></div>
<!--Psionics--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="psionics">Psionics</label> = <input type="text" class="sheet-csnInput" name="attr_psionicsname" value="" /></div>
<!--Spellcasting--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="spellcasting">Spellcasting</label> = <input type="text" class="sheet-csnInput" name="attr_spellcastingname" value="" /></div>
<!--Weird Science--><div class="sheet-csnItem"><label class="sheet-csnLabel" data-i18n="weird-science">Weird Science</label> = <input type="text" class="sheet-csnInput" name="attr_weirdsciencename" value="" /></div>
<fieldset class='repeating_spells'>
<label class="sheet-configlabels" data-i18n="button-behavior">Button Behavior</label>
<select name="attr_spellbutton" title="@{repeating_spells_$#_spellbutton}" class="sheet-spellbutton">
<option value="2" data-i18n="skill-only">Skill Only</option>
<option value="0" data-i18n="attack-and-damage-abbr">Atk + Dmg</option>
<option value="1" data-i18n="damage-only" selected>Damage Only</option>
</select>
<input class="sheet-spellbutton" type="hidden" name="attr_spellbutton" value="1" />
<div class='sheet-spellskill'>
<label class="sheet-configlabels" data-i18n="skill">Skill</label>
<div class="sheet-container">
<div class="sheet-child">
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-athletics" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="athletics" /><span name='attr_sathleticsname'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-faith" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="faith" checked /><span name='attr_sfaithname'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-focus" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="focus" /><span name='attr_sfocusname'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-performance" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="performance" /><span name='attr_sperformancename'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-psionics" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="psionics" /><span name='attr_spsionicsname'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-spellcasting" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="spellcasting" /><span name='attr_sspellcastingname'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-weirdscience" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="weirdscience" /><span name='attr_sweirdsciencename'></span></label>
<label class="sheet-ddmenu"><input type="radio" class="sheet-select-radio sheet-unskilled" name="attr_spellskill" title="@{repeating_spells_$#_spellskill}" value="unskilled" /><span data-i18n='unskilled'>Unskilled</span></label>
<input type="hidden" class="sheet-select-radio sheet-" name="attr_spellskill" value="faith" />
<div class="sheet-athletics"><span name='attr_sathleticsname'></span></div>
<div class="sheet-faith"><span name='attr_sfaithname'></span></div>
<div class="sheet-focus"><span name='attr_sfocusname'></span></div>
<div class="sheet-performance"><span name='attr_sperformancename'></span></div>
<div class="sheet-psionics"><span name='attr_spsionicsname'></span></div>
<div class="sheet-spellcasting"><span name='attr_sspellcastingname'></span></div>
<div class="sheet-weirdscience"><span name='attr_sweirdsciencename'></span></div>
<div class="sheet-unskilled"><span data-i18n='unskilled'>Unskilled</span></div>
</div>
</div>
</div>
</fieldset>
<script type="text/worker">
const spellskillnamelist = ["faithname","athleticsname","focusname","performancename","psionicsname","ritualname","spellcastingname","weirdsciencename"]; // similarly could consider a refactor
on("change:repeating_spells:spellbutton change:repeating_weapons:weaponbutton", function(eventInfo) {
console.log("iii sourceAttribute: " + eventInfo.sourceAttribute + " iii");
let parts = eventInfo.sourceAttribute.split('_');
let field, value;
if (parts[1] === "weapons") { field = weaponsskillnamelist; }
else { field = spellskillnamelist; }
if (eventInfo.newValue === "2" || eventInfo.newValue === "0") {
console.log("Make sure the drop down is populated with skill names");
setSkillDropdown(parts[1], field, "get names", parts[2]);
}
else {
console.log("No need to update anything...");
}
});
spellskilllist.forEach(spellskilllist => {
on(`change:${spellskilllist}name`, function(eventInfo) {
log("Spell Skill List","Skill Name Change","lime");
console.log("Triggering Attribute: " + eventInfo.sourceAttribute);
let field = "s" + eventInfo.sourceAttribute;
let value = eventInfo.newValue;
setSkillDropdown("spells", field, value);
});
});
function setSkillDropdown(section, field, value, rowid) {
let repsection = `repeating_${section}`;
let setskill = {};
if(Array.isArray(field) && value === "get names") {
//is Array
console.log("Field array: " + field);
repsection += `_${rowid}_`;
console.log("!!! Passed an Array !!!");
getAttrs(field, function(v) {
let setfield;
let fieldprefix;
let setvalue;
if (section === "weapons") {fieldprefix = "r";}
else {fieldprefix = "s";}
for (let a = 0; a < field.length; a++) {
console.log("iii section ID: " + rowid + " iii");
setfield = repsection + fieldprefix + field[a];
setvalue = v[field[a]];
console.log(`iii setfield: ${setfield} iii`);
console.log(`iii setvalue: ${setvalue} iii`);
setskill[setfield] = setvalue;
}
/*let defaultval = field[0].split('name');
if (section === "weapons") { setfield = repsection + "weaponskill"; }
else { setfield = repsection + "spellskill"; }
setskill[setfield] = defaultval;*/
console.log("Setting: " + JSON.stringify(setskill));
setAttrs(setskill);
});
}
else {
console.log("iii passed a single field, so need to update that single field iii");
getSectionIDs(repsection, function(idArray) {
//passing in a single field
for (let i = 0; i < idArray.length; i++) {
console.log(`${repsection}_${idArray[i]}_${field}: ${value}`);
setskill[`${repsection}_${idArray[i]}_${field}`] = value;
}
setAttrs(setskill);
});
}
}
</script> CSS : .sheet-spellbutton {
width: 100px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.sheet-spellskill {
display: none;
}
.sheet-spellbutton[value="0"] + .sheet-spellskill,
.sheet-spellbutton[value="2"] + .sheet-spellskill {
display: inline-block;
margin-left: 10px;
}
.sheet-container {
width: 100px;
border-bottom: 1px solid black;
}
.sheet-container,
.sheet-child {
display: inline-block;
}
.sheet-child {
vertical-align: middle;
width: 100px;
height: 28px;
}
.sheet-child label {
display: none;
z-index: 1;
}
.sheet-ddmenu {
font-weight: normal;
font-size: 1em;
width: 95%;
}
.sheet-child:hover {
border-radius: 10px;
background: silver;
position:absolute;
width: 100px;
margin-top: -14px;
height: auto;
z-index: 1;
padding: 5px;
}
.sheet-child:hover label {
display: inline-block;
margin-left: -5px;
}
div.sheet-athletics,
div.sheet-unskilled,
div.sheet-faith,
div.sheet-focus,
div.sheet-performance,
div.sheet-psionics,
div.sheet-spellcasting,
div.sheet-weirdscience {
width: 100px;
height: 28px;
line-height:28px;
color: black;
border-bottom: 1px solid black;
text-align: center;
display: none;
}
.sheet-child:not(:hover) input.sheet-select-radio[value="athletics"] ~ div.sheet-athletics,
.sheet-child:not(:hover) input.sheet-select-radio[value="unskilled"] ~ div.sheet-unskilled,
.sheet-child:not(:hover) input.sheet-select-radio[value="faith"] ~ div.sheet-faith,
.sheet-child:not(:hover) input.sheet-select-radio[value="focus"] ~ div.sheet-focus,
.sheet-child:not(:hover) input.sheet-select-radio[value="performance"] ~ div.sheet-performance,
.sheet-child:not(:hover) input.sheet-select-radio[value="psionics"] ~ div.sheet-psionics,
.sheet-child:not(:hover) input.sheet-select-radio[value="spellcasting"] ~ div.sheet-spellcasting,
.sheet-child:not(:hover) input.sheet-select-radio[value="weirdscience"] ~ div.sheet-weirdscience {
display: block;
}
label.sheet-ddmenu:hover {
background-color: orange;
}
.sheet-child:hover > label.sheet-ddmenu > .sheet-select-radio:checked + span {
font-weight: bold;
font-size: 1em;
} Here's the output to the console of the object being passed into the setAttrs function: Setting: {"repeating_spells_-ma1clcdjg30hftolte9_sfaithname":"Faith","repeating_spells_-ma1clcdjg30hftolte9_sathleticsname":"Athletics","repeating_spells_-ma1clcdjg30hftolte9_sfocusname":"Focus","repeating_spells_-ma1clcdjg30hftolte9_sperformancename":"Performance","repeating_spells_-ma1clcdjg30hftolte9_spsionicsname":"Psionics", "repeating_spells_-ma1clcdjg30hftolte9_sspellcastingname":"Spellcasting","repeating_spells_-ma1clcdjg30hftolte9_sweirdsciencename":"Weird Science" } The bolded/Italicized bit is where it dies...everything before that is set properly on the sheet.