Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Dynamic field in DCT with Replicants.
vp98aa
Hi,
I have the following (see below) datacapture.cfg. Basically what I want to do is show a certain field based on what was selected in another field. I got that to work perfectly fine. But I am running into problems with Replicants. The version below is a simplified version of what I have. I could have 4 or 5 or more levels of replication and within that I could have a field that I want to hide or show.
But on the bright side whatever field I select (agent type) and the field that I want to actually hide to show are on the same replicant. So how do I do that? How do I know which replicant (remember several nested and several levels deep) I am on?
any help would be appreciated.
Thanks
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-capture-requirements SYSTEM "datacapture5.0.dtd">
<data-capture-requirements name="" type="content">
<ruleset name="TeamSite Templating">
<script><![CDATA[
function init() {
/* This line sets the Item Handler so that it know to call the "setDctFields" method when the region option changes. */
IWEventRegistry.addItemHandler("/region", "onItemChange", setDctFields);
/* We are CHEATERS. We are setting the agent to invisible when the DCT inits. */
IWDatacapture.getItem("/agent[1]/IllinoisAgents").setVisible(false);
IWDatacapture.getItem("/agent[1]/IowaAgents").setVisible(false);
}
function setDctFields() {
/* This gets us the Region Item. */
var regionItem = IWDatacapture.getItem("/region");
/* This gets us all the options for Region Item */
var regionOptions = regionItem.getOptions();
/* This gets us the value of the option selected. */
var regionValue = regionOptions[parseInt(regionItem.getValue())].value;
/* Logic to hide or show the fields. */
if(regionValue == "IA"){
IWDatacapture.getItem("/agent[1]/IllinoisAgents").setVisible(false);
IWDatacapture.getItem("/agent[1]/IowaAgents").setVisible(true);
}
else if (regionValue == "IL"){
IWDatacapture.getItem("/agent[1]/IowaAgents").setVisible(false);
IWDatacapture.getItem("/agent[1]/IllinoisAgents").setVisible(true);
}
else {
IWDatacapture.getItem("/agent[1]/IllinoisAgents").setVisible(false);
IWDatacapture.getItem("/agent[1]/IowaAgents").setVisible(false);
}
/* Redraw or reload the DCT so that the new field(s) show up */
IWDatacapture.redraw();
}
//Now do the initialization...
init();
]]></script>
<item name="region">
<label>Region</label>
<description>Region</description>
<select>
<option selected="t" value="" label="Select a region"/>
<option value="IA" label="Iowa"/>
<option value="IL" label="Illinois"/>
</select>
</item>
<item name="agent">
<replicant min="1" max="99" default="1" combination="and" hide-name="f">
<item name="IllinoisAgents">
<label>Illinois Agents</label>
<database data-type="VARCHAR(350)"/>
<description>Select one or more search topics. CTRL + Click for multiple.</description>
<select multiple="t" size="5">
</select>
</item>
<item name="IowaAgents">
<label>Iowa Agents</label>
<database data-type="VARCHAR(350)"/>
<description>Select one or more search topics. CTRL + Click for multiple.</description>
<select multiple="t" size="5">
</select>
</item>
</replicant>
</item>
</ruleset>
</data-capture-requirements>
Find more posts tagged with
Comments
Michael
Hi
The first thing you want to do is accept the item as a parameter in your event handler - ie:
change:
function setDctFields() {
to:
function setDctFields(item) {
The item which triggered the event will be passed to your function by the framework.
Once you know the item which triggered the event it is reasonably easy for you to use item.getName() and then modify the string appropriately to target the fields you wish to show or hide.
Hope this helps.
Cheers,
Michael