Environment: TS 7.3.2 on Linux
Scenario:
I have a DCT that contains an replicant OR conainer that looks essentially like this:
<container name="slide" location="slide" min="0" max="unbounded" default="0" combination="or">
<label>Slide</label>
<container name="image" location="image">
<label>Image</label>
...
</container>
<container name="audio" location="audio">
<label>Audio</label>
...
</container>
...
</container>
I create a DCR from it, and in [semi-]collapsed mode I see N "Slide" container label-headings.
I decided, I'd like to augment those labels so that they include the type of slide inside, so I created the following code:
function init() {
if (IWDCRInfo.getDCRName() != "") {
resetSlideLabels();
}
IWEventRegistry.addItemHandler("/root/slide", "onReplicantAdded", resetLabel);
}
function resetSlideLabels() {
var children = IWDatacapture.getItem("/root/slide").getChildren();
for (var i in children) {
resetLabel(children[i]);
}
}
function resetLabel(item) {
console.log("reset label on "+item.getName());
var kids = item.getChildren();
console.log(" -> "+item.getLabel()+" : "+kids[0].getLabel()); item.setLabel(item.getLabel()+" : "+kids[0].getLabel());
console.log("done"); return true;
}
So - I bring up an existing DCR with 5 slides in it - the code works just great, and I can see in the console log:
resetLabel on /root/slide[1]
-> Slide : Image
done
...
resetLabel on /root/slide[5]
-> Slide : Audio
done
Great!
Problem
Now I go to add a new slide in 3rd position, the replicant never gets added and I see the following in the console log:
resetLabel on /root/slide[3]
-> Slide : Image
TypeError: titleElement is nulltitleElement.innerHTML = HTMLEscape(item.label);
[dc_actions.js (line 106)]
I was obviously able to derefernce both the item and the child-item to get their respective labels in order to display the second debugging line (-> Slide : Image) so it has to be failing on the item.setLabel() line, a line that worked just fine 5 times in a row on pre-existing elements.
I'm a bit stymied by this: It's a post-process event handler, I appear to have access to both the parent and child IWItems and their respective labels, but it dies when I try to actually modify the label on the newly created [child] instance. It's not like I can put conditionals around anything in my code to test for null-ness and such, because it would all pass through and still fail where it is now.
Any ideas?