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)
Show Hide Items In Replicants via JS
bgeorge
Hey All,
I have the following datacapture file:
<script language="javascript" location="template-type" src="content-validation.js" />
Content
Type
This identifies whether the content is a block or inline element. A block element is an encapsulated section of content such as a paragraph or table. An inline element is a snippet of content that resides within another element for example a meta attribute. If inline is selected, all paragraph and line break tags will be stripped from the content.
Key
This identifies an element of content in the set. The key value must be a unique alphanumeric word (no spaces).
Description
This is an optional description of the content. This field has no impact on the generated output.
Body
This is the content field.
<br> external-editor-config="jaguar"<br> external-editor-inline="f" wrap="off"/><br> </item><br> <item name="code" pathid="code"><br> <label>Code</label><br> <description><br> This is code view field.<br> </description><br> <text required="t" maxlength="5000" /><br> </item><br></container><br><br></root-container><br></ruleset><br></data-capture-requirements><br><br>I am trying to write a event handler that will show/hide the "code" and "body" elements of the "content" replicant based on whether the user selects the "code" radio button (show "code" text field item, hide "body" item), or the "block"/"inline" radio button (hide "code" text field item, show "body" item). To do this, I have written the following JS code:<br><br>function init() {<br> IWEventRegistry.addFormHandler("onSaveValid", validateForm);<br> IWEventRegistry.addFormHandler("/content-set/content/type", onItemChange, changeHTMLView);<br> <br> changeHTMLView( IWDatacapture.getItem("/content-set/content/type") );<br>}<br><br>function validateForm() {<br> var content = IWDatacapture.getItem("/content-set/content").getChildren();<br> if (content.length == 1) return true;<br><br> var keys = new Array();<br> for (var i=0; i<content.length; i++) {<br> var item = content<i>.getChildByName("key");<br> if (keys[item.getValue()] == null) {<br> keys[item.getValue()] = i;<br> }<br> else {<br> alert("Error: Duplicate key values. The keys must be unique.");<br> item.setFocus();<br> return false;<br> }<br> }<br> return true;<br>}<br><br>function changeHTMLView(item){<br> var flag = isTypeCode(item);<br> var type = getType(item);<br> <br> if( flag ) {<br> setItemStatus (IWDatacapture.getItem("/content-set/content/code"), flag);<br> setItemStatus (IWDatacapture.getItem("/content-set/content/body"), !flag);<br> }<br> else {<br> setItemStatus (IWDatacapture.getItem("/content-set/content/code"), !flag);<br> setItemStatus (IWDatacapture.getItem("/content-set/content/body"), flag);<br> }<br>}<br><br>function isTypeCode(typeItem) {<br> return (typeItem.getOptions()[typeItem.getValue()].value == "C");<br>}<br><br>function setItemStatus(item, status) {<br> item.setVisible(status);<br> item.setRequired(status);<br>}<br><br>IWEventRegistry.addFormHandler("onFormInit", init);<br><br>The resulting DCT displays all the correct radio buttons/fields, but the dynamic show/hide functionality doesn't work. I think my problem lies in trying to get a handle on the specific replicant that called the event handler. Any suggestions? Thanks.<br>The resulting DCT displays all the correct radio buttons/fields, but the dynamic show/hide functionality doesn't work. I think my problem lies in trying to get a handle on the specific replicant that called the event handler. Any suggestions? Thanks.
Find more posts tagged with
Comments
bgeorge
Hey All,
I have the following datacapture file:
<script language="javascript" location="template-type" src="content-validation.js" />
Content
Type
This identifies whether the content is a block or inline element. A block element is an encapsulated section of content such as a paragraph or table. An inline element is a snippet of content that resides within another element for example a meta attribute. If inline is selected, all paragraph and line break tags will be stripped from the content.
Key
This identifies an element of content in the set. The key value must be a unique alphanumeric word (no spaces).
Description
This is an optional description of the content. This field has no impact on the generated output.
Body
This is the content field.
<br> external-editor-config="jaguar"<br> external-editor-inline="f" wrap="off"/><br> </item><br> <item name="code" pathid="code"><br> <label>Code</label><br> <description><br> This is code view field.<br> </description><br> <text required="t" maxlength="5000" /><br> </item><br></container><br><br></root-container><br></ruleset><br></data-capture-requirements><br></html><br><br>I am trying to write a event handler that will show/hide the "code" and "body" elements of the "content" replicant based on whether the user selects the "code" radio button (show "code" text field item, hide "body" item), or the "block"/"inline" radio button (hide "code" text field item, show "body" item). To do this, I have written the following JS code:<br><br><code><br>function init() {<br> IWEventRegistry.addFormHandler("onSaveValid", validateForm);<br> IWEventRegistry.addFormHandler("/content-set/content/type", onItemChange, changeHTMLView);<br> <br> changeHTMLView( IWDatacapture.getItem("/content-set/content/type") );<br>}<br><br>function validateForm() {<br> var content = IWDatacapture.getItem("/content-set/content").getChildren();<br> if (content.length == 1) return true;<br><br> var keys = new Array();<br> for (var i=0; i<content.length; i++) {<br> var item = content<i>.getChildByName("key");<br> if (keys[item.getValue()] == null) {<br> keys[item.getValue()] = i;<br> }<br> else {<br> alert("Error: Duplicate key values. The keys must be unique.");<br> item.setFocus();<br> return false;<br> }<br> }<br> return true;<br>}<br><br>function changeHTMLView(item){<br> var flag = isTypeCode(item);<br> var type = getType(item);<br> <br> if( flag ) {<br> setItemStatus (IWDatacapture.getItem("/content-set/content/code"), flag);<br> setItemStatus (IWDatacapture.getItem("/content-set/content/body"), !flag);<br> }<br> else {<br> setItemStatus (IWDatacapture.getItem("/content-set/content/code"), !flag);<br> setItemStatus (IWDatacapture.getItem("/content-set/content/body"), flag);<br> }<br>}<br><br>function isTypeCode(typeItem) {<br> return (typeItem.getOptions()[typeItem.getValue()].value == "C");<br>}<br><br>function setItemStatus(item, status) {<br> item.setVisible(status);<br> item.setRequired(status);<br>}<br><br>IWEventRegistry.addFormHandler("onFormInit", init);<br></code><br><br>The resulting DCT displays all the correct radio buttons/fields, but the dynamic show/hide functionality doesn't work. I think my problem lies in trying to get a handle on the specific replicant that called the event handler. Any suggestions? Thanks.<br>The resulting DCT displays all the correct radio buttons/fields, but the dynamic show/hide functionality doesn't work. I think my problem lies in trying to get a handle on the specific replicant that called the event handler. Any suggestions? Thanks.