tag:help-archives.hannonhill.com,2010-02-09:/discussions/how-do-i/16519-get-checkbox-value-using-block-locator-toolCascade CMS: Discussion 2017-09-13T21:40:50Ztag:help-archives.hannonhill.com,2010-02-09:Comment/360621822015-02-16T19:22:14Z2015-02-16T19:22:14ZGet checkbox value using block locator tool<div><p>I am allowing users to add multiple blocks to a page and i'm
using the locator tool to extract the content from the block. On
each block, I have given the user a checkbox for a few options -
i.e. if they want a header, if they want to include a picture, etc.
In my velocity, I need to check those options and display things
accordingly. It seems I'm getting into my block correctly but I
can't run a check on the checkbox values.</p>
<p>Sample XML for Block I'm trying to extract the information from
(include-header is the checkbox):</p>
<pre>
<code><system-data-structure>
<page-element>
<include-header>
<value>Yes</value>
</include-header>
<content-type>Text (w/ Supporting Media)</content-type>
<header>
<text>This is the header</text>
<heading-level>Heading 2</heading-level>
</header>
</page-element>
</system-data-structure></code>
</pre>
<p>When I run the properties tool I get:</p>
<pre>
<code>Object type: com.hannonhill.cascade.api.adapters.XHTMLDataDefinitionBlockAPIAdapter
Properties:
- lastModified: Date
- dataDefinitionPath: String
- parentFolder: Folder
- identifier: PathIdentifier
- getStructuredDataNode(String): StructuredDataNode
- isUserCanWrite(String): boolean
- structuredData: StructuredDataNode[]
- currentUserCanWrite: boolean
- createdOn: Date
- metadata: Metadata
- folderOrder: int
- parentFolderIdentifier: PathIdentifier
- createdBy: String
- identifer: Identifier
- path: String
- lastModifiedBy: String
- currentUserCanRead: boolean
- isUserCanRead(String): boolean
- hideSystemName: boolean
- xHTML: String
- siteName: String
- siteId: String
- xHTMLAsXMLElement: Element
- name: String
- getStructuredDataNodes(String): StructuredDataNode[]</code>
</pre>
<p>I've tried the following but everything is still saying object
is null:</p>
<pre>
<code>#set ( $headings = $local_block.getStructuredDataNodes("page-element/include-header"))
#set ( $headings = $local_block.getStructuredDataNode("page-element/include-header/value").value)
#set ( $headings = $local_block.getStructuredDataNode("page-element/include-header").value)
#set ( $headings = $local_block.getStructuredDataNode("page-element/include-header/value").textValue)
#set ( $headings = $local_block.getStructuredDataNode("page-element/include-header").textValue)</code>
</pre></div>sbarre5tag:help-archives.hannonhill.com,2010-02-09:Comment/360621822015-02-16T19:53:25Z2015-02-16T19:53:25ZGet checkbox value using block locator tool<div><p>Hi,</p>
<p>For checkbox, radio and multi-select fields, you will want to
use is the <code>textValues</code> property for the field, which
will return an array of each checked/selected value. You can use
the <a href=
"http://www.hannonhill.com/kb/Script-Formats/#property-tool">Property
Tool</a> to see the available properties for the
StructuredDataNodeAPIAdapter.</p>
<p>Note: there is a <a href=
"https://hannonhill.jira.com/browse/CSI-755">known defect</a> in
which the first item in the returned array is empty, so the array
basically starts at index 1. The following should return your
value:</p>
<pre>
<code>$local_block.getStructuredDataNode("page-element/include-header").textValues.get(1)</code>
</pre>
<p>Also, you may want to check the size of the array prior to
attempting to use <code>.get(1)</code> to avoid an IndexOutOfBounds
error. Because of the known defect, you basically need to check to
see if the size is greater that 1 (or equal to 2 if you know for a
fact there will only ever be one checkbox):</p>
<pre>
<code>#set ($headings = $local_block.getStructuredDataNode("page-element/include-header").textValues)
#if ($headings.size() == 2)
## ... do something with the value "Yes"
$headings.get(1)
#end</code>
</pre>
<p>Please let me know if you have any questions.</p>
<p>Thanks!</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/360621822015-02-16T20:01:55Z2015-02-16T20:01:55ZGet checkbox value using block locator tool<div><p>I didn’t even know textValue(s) was even a thing. As
usual, worked like a charm!</p>
<p>Saundra Barrett<br>
Senior Web Developer<br>
Emory University, Web Design Group<br>
Office: 404-727-3437<br>
Cell: 404-670-1238</p></div>sbarre5tag:help-archives.hannonhill.com,2010-02-09:Comment/360621822015-02-16T20:16:23Z2015-02-16T20:16:23ZGet checkbox value using block locator tool<div><p>Thank you for following up, Saundra. I am glad to hear the
proposed change did the trick.</p>
<blockquote>
<p>I didn’t even know textValue(s) was even a thing</p>
</blockquote>
<p>You were definitely on the right track when you tried
<code>textValue</code>, since it is technically a "text" field. The
difference is you can have multiple checkbox "items" per field, so
you need to account for that by using <code>textValues</code> which
will return an array.</p>
<p>Perhaps an improvement could be to allow for
<code>textValue</code> to return the checked/selected value for
checkboxes and multi-selects if only one value is present, or for
radio fields since you can only ever have one value. I went ahead
and <a href="https://hannonhill.jira.com/browse/CSI-856">logged an
improvement</a> for this functionality. Feel free to use this link
to track the progress of this improvement or keep an eye out for it
on our <a href="http://www.hannonhill.com/kb/Release-Notes">Release
Notes site</a>.</p>
<p>I'm going to go ahead and close this discussion, please feel
free to comment or reply to re-open if you have any additional
questions.</p>
<p>Have a great day!</p></div>Ryan Griffith