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 validations on replicant
apsmiles
Hi all,
I want to enable or disable some childern of a replicant container/item. I am able to do it for the first child, i.e. the child which is shown on first load, but those validations don't work when new childern are added (by clicking on the '+' button in UI). Can anybody tell me some workaround to it.
Thanks,
Anil
Find more posts tagged with
Comments
Bill Klish
What version of TeamSite are you using?
There are some new features in TeamSite 6.5 Form API that provide more robust support for replicants and containers. It is not clear whether you are trying to handle enabling or disabling children or validating fields. Please give us a little more information so we can help you.
apsmiles
I am using TS 6.5, Win 2K.
My aim is to enable/disable or "setrequired", a few of replicant fields on change of some item say radio button. It is working fine, but these validations happen only to the currently displayed children of the replicant. But once the user adds more fields of it, the validations don't work.
Anil
Adam Stoller
Well, you're using the best version [thus far] for handling replicants / containers with FormAPI - so the next questions are:
Can you supply a copy of the DCT?
Can you supply the code you are currently using (if not directly embedded within the DCT) so that we can see what you *have* done, and then we might be able to propose alterations for what you want to be able to do?
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
apsmiles
I am copying the code..There are two codes, the first one calls the second one by inline command. These two are followed by the javascript validation code.
The logic is in the code two, if a user selects the relatedLinkModule->type->1, then only "typeOne" container is visible (& all fields required) and the rest becomes invisible. similarly for 2,3 and 4.
Now the problem is if the relatedLinkModule is more than one then the validations doesnt work.
===================================
CODE 1 ---------------->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data-capture-requirements SYSTEM "datacapture6.0.dtd">
<!--
########################################
NAME
datacapture.cfg
DESCRIPTION
This xml file configures the "Service Hub Page" DCT to capture content.
COPYRIGHT
2004 of Nextel Communication
AUTHOR
Nextel Communication
REVISION
Desc Ver 1 : 11/29/2004 : Dipika Jain : Created the file
########################################a
-->
<data-capture-requirements name="serviceHub">
<ruleset name="serviceHub">
<script language="javascript" location="webserver" src="/iw/javascript/relatedLinkModules.js"/>
<script language="javascript" location="webserver" src="/iw/javascript/onCheckRequired.js"/>
<script language="javascript" location="webserver" src="/iw/javascript/browsePathRegex.js"/>
<script language="javascript" location="webserver" src="/iw/javascript/onCheckEnableDisable.js"/>
<script language="javascript" location="template-type">
<![CDATA[
var dctName = "serviceHub";
var i=0;
var regex;
var activeContainers;
var activeOuterContainers;
var itemName;
var itemFullName;
function init()
{
relatedModuleInit();
billboardInit();
}
function setRegex()
{
var res;
var result = true;
var errString = "Enter correct value for: " + "\n" ;
regex = /(assets_images|assets_flash)/;
activeContainers = IWDatacapture.getItem("/serviceHub/brandingImage/imageFile");
res = browsePathRegex(activeContainers, regex, "false");
if(!res){
result = false;
errString = errString + eval(activeContainers).getName() + "\n";
}
var billboardImg1 = IWDatacapture.getItem("/serviceHub/billboard1/imageFile").getValue();
var billboardImg2 = IWDatacapture.getItem("/serviceHub/billboard2/imageFile").getValue();
if ( (billboardImg1 != "") || (billboardImg2 != "") )
{
activeContainers = IWDatacapture.getItem("/serviceHub/billboard1/imageFile");
res = browsePathRegex(activeContainers, regex, "false");
if(!res){
result = false;
errString = errString + eval(activeContainers).getName() + "\n";
}
activeContainers = IWDatacapture.getItem("/serviceHub/billboard2/imageFile");
res = browsePathRegex(activeContainers, regex, "false");
if(!res){
result = false;
errString = errString + eval(activeContainers).getName() + "\n";
}
}
var billboardImg3 = IWDatacapture.getItem("/serviceHub/billboard3/imageFile").getValue();
if (billboardImg3 != "")
{
activeContainers = IWDatacapture.getItem("/serviceHub/billboard3/imageFile");
res = browsePathRegex(activeContainers, regex, "false");
if(!res){
result = false;
errString = errString + "\n" + eval(activeContainers).getName() + "\n";
}
}
if(!result){
alert(errString);
}
return result;
}
IWEventRegistry.addFormHandler("onFormInit", init);
IWEventRegistry.addFormHandler("onSave", setRegex);
]]>
</script>
<root-container name="serviceHub" location="serviceHub">
<item name="serviceGroupName" pathid="serviceGroupName">
<label> Service Group Name</label>
<description>Displays name of service group </description>
<textarea required="t" wrap="virtual" external-editor="visualformat" external-editor-config="visualformatconfig.xml" rows="20" cols="70" validation-regex="^(.|\n){1,4000}$"></textarea>
</item>
<container name="serviceGroupNameImage" location="serviceGroupNameImage">
<label>Service Group Name Image</label>
<description>Displays page header image at top of hub page</description>
<item name="imageFile" pathid="imageFile">
<label>Select Image File</label>
<browser maxlength="4000" required="t" initial-dir="/assets_images/" ceiling-dir="/assets_images/"/>
</item>
<item name="altText" pathid="altText">
<label>Alt text </label>
<text required="t" size="70" maxlength="255"/>
</item>
</container>
<item name="largeTextDetails" pathid="largeTextDetails">
<label>Large Text Details</label>
<description>Large text body copy on service hub page. </description>
<textarea required="t" wrap="virtual" external-editor="visualformat" external-editor-config="visualformatconfig.xml" rows="20" cols="70" validation-regex="^(.|\n){1,4000}$"></textarea>
</item>
<item name="smallTextDetails" pathid="smallTextDetails">
<label>Small Text Details</label>
<description>Regular text body copy on service hub page</description>
<textarea required="t" wrap="virtual" external-editor="visualformat" external-editor-config="visualformatconfig.xml" rows="20" cols="70" validation-regex="^(.|\n){1,4000}$"></textarea>
</item>
<container name="brandingImage" location="brandingImage">
<label>Branding Image</label>
<description>Select branding image in place of local navigation (required)</description>
<item name="imageFile" pathid="imageFile">
<label>Image/Flash File</label>
<browser maxlength="4000" required="t" initial-dir="/" ceiling-dir="/"/>
</item>
<item name="altText" pathid="altText">
<label>Alt Text</label>
<text required="t" size="70" maxlength="255"/>
</item>
</container>
<item name="associatedServicesSectionHeader" pathid="associatedServicesSectionHeader">
<label>Associated Services Section Header </label>
<description>Display heading above services section on service hub page.</description>
<text required="t" size="70" maxlength="255"/>
</item>
<container name="associatedServiceDetails" location="associatedServiceDetails" min="1" max="10">
<label>Associated Service Details</label>
<description>Choose the Service DCRs that will appear on service hub page (maximum 10)</description>
<item name="serviceRawDetailDCR" pathid="serviceRawDetailDCR">
<label>Service Raw Detail DCR </label>
<browser maxlength="4000" required="t" initial-dir="/templatedata/services/serviceRawDetail/data/" ceiling-dir="/templatedata/services/serviceRawDetail/data/"/>
</item>
</container>
<inline command ="/bin/cat /opt/appl/cms/dct/inline/Billboard.xml"/>
<item name="abstract" pathid="abstract">
<label>Abstract</label>
<description>Enter short description of service group to display on service landing page</description>
<textarea required="t" wrap="virtual" external-editor="visualformat" external-editor-config="visualformatconfig.xml" rows="20" cols="70" validation-regex="^(.|\n){1,4000}$">
</textarea>
</item>
========================================================================================
CODE 2 IS CALLED HERE ................
=======================================================================================
<inline command ="/bin/cat /opt/appl/cms/dct/inline/RelatedModules.xml"/>
</root-container>
</ruleset>
</data-capture-requirements>
===========================================================================================================
===========================================================================================================
CODE 2 -------------------------------------------->
<?xml version="1.0" encoding="UTF-8"?>
<substitution>
<container name="relatedLinkModule" location="relatedLinkModule" min="0" max="3">
<!-- There can only be 3 elements in this container -->
<label>All Related Modules</label>
<description>Display related links(maximum 3 modules)</description>
<item name="selectionTitle" pathid="selectionTitle">
<label>Selection Title</label>
<text size="70" maxlength="255"/>
</item>
<item name="type" pathid="type">
<label>Type</label>
<select>
<option label="Type One" value="1"/>
<option label="Type Two" value="2"/>
<option label="Type Three" value="3"/>
<option label="Type Four" value="4"/>
</select>
</item>
<container name="typeOne" location="typeOne">
<label>Type One</label>
<container name="links" location="links" min="1" max="5">
<label>Links</label>
<item name="linkLabel" pathid="linkLabel">
<label>Link Label</label>
<text size="70" maxlength="255"/>
</item>
<item name="linkUrl" pathid="linkUrl">
<label>Link Url</label>
<browser maxlength="4000" initial-dir="/" ceiling-dir="/"/>
</item>
</container>
</container>
<container name="typeTwo" location="typeTwo">
<label>Type Two</label>
<container name="imageAbstract" location="imageAbstract" min="1" max="2">
<label>Image/Abstract</label>
<item name="abstract" pathid="abstract">
<label>Abstract</label>
<textarea cols="70" rows="10" wrap="virtual" validation-regex="^(.|\n){1,4000}$" />
</item>
<item name="image" pathid="image">
<label>Image</label>
<browser maxlength="4000" initial-dir="/en_assets/images/" ceiling-dir="/en_assets/images"/>
</item>
<item name="altText" pathid="altText">
<label>Alt Text</label>
<text size="70" maxlength="255"/>
</item>
<item name="linkLabel" pathid="linkLabel">
<label>Link Label</label>
<text size="70" maxlength="255"/>
</item>
<item name="linkUrl" pathid="linkUrl">
<label>Link Url</label>
<browser maxlength="4000" initial-dir="/" ceiling-dir="/"/>
</item>
</container>
</container>
<container name="typeThree" location="typeThree">
<label>Type Three</label>
<container name="abstractLink" location="abstractLink" min="1" max="3">
<label>Abstract/Link</label>
<item name="abstract" pathid="abstract">
<label>Abstract</label>
<textarea cols="70" rows="10" wrap="virtual" validation-regex="^(.|\n){1,4000}$" />
</item>
<item name="linkLabel" pathid="linkLabel">
<label>Link Label</label>
<text size="70" maxlength="255"/>
</item>
<item name="linkUrl" pathid="linkUrl">
<label>Link Url</label>
<browser maxlength="4000" initial-dir="/" ceiling-dir="/"/>
</item>
</container>
</container>
<container name="typeFour" location="typeFour">
<label>Type Four</label>
<container name="linkAbstract" location="linkAbstract" min="1" max="5">
<label>Link/Abstract</label>
<item name="linkLabel" pathid="linkLabel">
<label>Link Label</label>
<text size="70" maxlength="255"/>
</item>
<item name="linkUrl" pathid="linkUrl">
<label>Link Url</label>
<browser maxlength="4000" initial-dir="/" ceiling-dir="/"/>
</item>
<item name="abstract" pathid="abstract">
<label>Abstract</label>
<textarea cols="70" rows="10" wrap="virtual" validation-regex="^(.|\n){1,4000}$" />
</item>
</container>
</container>
</container>
</substitution>
=====================================================================================================================
======================================
Javascript Code
FUNCTION:
init
DESCRIPTION:
This function gets called on load of the form
INPUT:
OUTPUT:
*/
function relatedModuleInit(){
alert("inside init"+dctName);
IWEventRegistry.addItemHandler("/" + dctName + "/relatedLinkModule[1]/type", "onItemChange", setReplicantNumber);
parent.IWDCEventRegistry.addListener("onItemAdded", handleItemAdded);
}
function handleItemAdded(item){
alert("inside handleItemAdded");
var xpath = getXPath(item);
if ( xpath.match('/relatedLinkModule\\[\\d+\\]$')) {
xpath = xpath+"/type";
//setReplicantNumber(IWDatacapture.getItem(xpath));
IWEventRegistry.addItemHandler(xpath, "onItemChange", setReplicantNumber);
}
}
function getXPath(item){
var xpath = null;
if ( typeof( item.getXPath ) != 'undefined' ) {
xpath = item.getXPath();
}
else {
xpath = item.getName();
}
return( xpath);
}
function setReplicantNumber(changedItem){
var xpath = getXPath(changedItem);
var item1 = IWDatacapture.getItem("/" + dctName + "/relatedLinkModule[1]/type");
var item2 = IWDatacapture.getItem("/" + dctName + "/relatedLinkModule[2]/type");
var item3 = IWDatacapture.getItem("/" + dctName + "/relatedLinkModule[3]/type");
if(xpath == item1.getName())
i=1;
else if(xpath == item2.getName())
i=2;
else if(xpath == item3.getName())
i=3;
setTypeFields(IWDatacapture.getItem(xpath));
}
function setTypeFields(changedItem){
var value = changedItem.getValue();
if (value == 0){
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeOne").setVisible(true);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeTwo").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeThree").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeFour").setVisible(false);
}
else if (value == 1){
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeOne").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeTwo").setVisible(true);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeThree").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeFour").setVisible(false);
}
else if (value == 2){
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeOne").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeTwo").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeThree").setVisible(true);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeFour").setVisible(false);
}
else if (value == 3){
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeOne").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeTwo").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeThree").setVisible(false);
IWDatacapture.getItem("/" + dctName + "/relatedLinkModule["+i+"]/typeFour").setVisible(true);
}
IWDatacapture.redraw();
}
===========================================================================================================
Adam Stoller
I have some problems visually compiliing javascript code - and it's kind of difficult to do anything more than that with this unless I take the time to recreate your code in my environment - which I don't feel like doing right now - so there may be some errors here.
The first thing I see that is questionable is:
IWEventRegistry.addItemHandler("/" + dctName + "/relatedLinkModule
[1]
/type", "onItemChange", setReplicantNumber);
I believe you want to leave out the
[1]
so that your ItemHandler is registered for *all* instances of
relatedLinkModule
rather than just for the first instance.
The next questionable item is:
parent.
IW
DC
EventRegistry.
addListener
("
onItemAdded
", handleItemAdded);
Where is this
IW
DC
EventRegistry
piece coming from? It's not documented in the 6.5 manual. Though there is an
IWEventRegistry
-- so if you're using something that's been reverse-engineered by someone, it's completely unsupported and has potential to stop working at any point in time. Additionally, if you
intended
to use
IWEventRegistry
, there's no
addListener
nor "
onItemAdded
", though there is an
addItemHandler
and "
OnReplicantAdded
" event name.
I suggest you spend some time with the 6.5 FormAPI guide and work through your deisgn a bit more - I think you will probably be able to get rid of a bunch of code you have by replacing it with a few other lines of code.
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
apsmiles
Thanx Ghoti,
I got the clue and the code is working fine now.
Regards,
Anil
Mohan_Babu
Hi Anil,
Can it be implemented in 5.5.2.. if yes, can you send a small piece of code, from which i can get an idea..
even i am facing the same problem as you had faced, but in 5.5.2..
Thanks and Regards
Mohan