I'm hoping someone out there can help me with some code. I've seen a number of posts on similar issues with replicants and FormAPI but haven't found the answer.
I have a replicant (
if it's still called that now I'm not using the replicant element and just defining min/max attribute values for a container) with 5 items in it - contentType, subheading, paragraph, image, imageCaption. The value of the top item "contentType" will be either "text" or "image" and the user's selection of this determines which of the other items to show in the container (i.e. if it's "text" show "subheading" and "paragraph" but hide the image related fields and vice versa).
I've managed to code the onChange event so that each replicant happily shows you different items depending on your choice of "text" or "image" but I'm having trouble initialising it for both new and existing DCRs.
My DCT conforms to datacapture6.0.dtd and the relevant bit is as follows:
<container name="content" min="1" max="20" location="content" combination="and">
<label>Content Blocks</label>
<item name="contentType" pathid="contentType" default="text">
<label/>
<radio required="f">
<option selected="t" value="text" label="Text"/>
<option value="image" label="Image"/>
</radio>
</item>
<item name="subheading" pathid="subheading">
<label>Section Heading</label>
<text required="f" maxlength="255"/>
</item>
<item name="paragraph" pathid="paragraph">
<label>Paragraph</label>
<textarea cols="50" external-editor="visualformat" external-editor-inline="t" required="f" rows="10" wrap="off"/>
</item>
<item name="imageCaption" pathid="imageCaption">
<label>Image Caption</label>
<description>A caption for use in the alt title of the displayed image.</description>
<text required="f" maxlength="255"/>
</item>
<item name="image" pathid="image">
<label>Full Image</label>
<browser extns=".gif,.jpg" initial-dir="/images/fullsize"/>
</item>
</container>
I've attached my javascript - including all rambling and commented debug code. You can see where the onChange is working and where I'm trying to work out how to initialise the state of the replicant items in the init() function. I thought I'd be able to use getChildren() but have had little success. I thought getChildren would return an array of all the replicant instances. But I've discovered through trial and error that I can't do a getChildren for the replicant array as a whole but if I do getChildren on a single instance of the replication item will give me all the item names *within* that single replicant rather than giving me the number of replications. Which isn't what i want at all!!
Basically what I want to do is write a loop passing
for(x=1;x<___THIS_IS_THE_VALUE_I_CAN'T_GET___;x++){
typeHandler(IWDatacapture.getItem("/standard/content["+x+"]/contentType"));
}
I just don't know how to get the value for the number of instances of my replicant to enable me to loop through.
If you got this far and still understand what I'm on about - well done - and thanks for taking the time to look through this.
cheers
Ani