<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stefan Cameron on Forms &#187; Scripting</title>
	<atom:link href="http://forms.stefcameron.com/category/scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://forms.stefcameron.com</link>
	<description>Building intelligent forms using Adobe LiveCycle Designer</description>
	<lastBuildDate>Wed, 16 Feb 2011 22:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Final Post: XFA Tank Wars</title>
		<link>http://forms.stefcameron.com/2010/12/03/final-post-xfa-tank-wars/</link>
		<comments>http://forms.stefcameron.com/2010/12/03/final-post-xfa-tank-wars/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 22:00:42 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Instance Manager]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/?p=602</guid>
		<description><![CDATA[Dear Readers and Fellow Form Developers, The time has come for me to focus my extra energy on other goals and projects at Adobe and at home. I have thoroughly enjoyed helping the XFA community for these past 4.5 years. All of the content on this blog was a direct result of your questions and [...]]]></description>
			<content:encoded><![CDATA[<p>Dear Readers and Fellow Form Developers,</p>
<p>The time has come for me to focus my extra energy on other goals and projects at Adobe and at home.</p>
<p>I have thoroughly enjoyed helping the XFA community for these past 4.5 years. All of the content on this blog was a direct result of your questions and I learned a great deal about Adobe&#8217;s <a href="http://partners.adobe.com/public/developer/xml/index_arch.html">XFA technology</a> and its <a href="http://adobe.com/go/livecycle">LiveCycle Enterprise Suite</a> along the way. <strong>Thank you!</strong></p>
<p>I leave you now with a final &#8220;form to end all forms&#8221; (in my mind, anyway): A version of the classic <a href="http://forms.stefcameron.com/xfa-tank-wars/">Tank Wars game</a> implemented entirely in XFA + JavaScript.</p>
<p>Why do this, you wonder? Well, it was a good challenge, you couldn&#8217;t embed <a href="http://blogs.adobe.com/formfeed/2010/12/flash-in-xfa-sample-column-chart.html">Flash in an XFA form</a> back then and I wanted to do something that would really put LiveCycle Designer&#8217;s Script Editor through its usability paces.</p>
<p>Comments are now closed on all posts and pages except for this one and the <a href="http://forms.stefcameron.com/xfa-tank-wars/">XFA Tank Wars</a> page which will close on December 31, 2010. I will continue to host this blog for your reference and bookmarks however I cannot guarantee it will be available forever.</p>
<p>Good luck on all your present and future form development projects.</p>
<p>Stefan</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2010/12/03/final-post-xfa-tank-wars/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Show the List of a Drop Down List</title>
		<link>http://forms.stefcameron.com/2010/05/31/show-the-list-of-a-drop-down-list/</link>
		<comments>http://forms.stefcameron.com/2010/05/31/show-the-list-of-a-drop-down-list/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 03:06:12 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/?p=548</guid>
		<description><![CDATA[Did you know that the list portion of a drop down list field can be displayed programmatically? You can set focus to the field and force its drop list to be displayed all in a single API call: xfa.host.openList(@object) xfa.host.openList(@string) -- deprecated since XFA 2.6 where @object is a reference to the drop down list [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that the list portion of a drop down list field can be displayed programmatically? You can set focus to the field and force its drop list to be displayed all in a single API call:</p>
<pre><code>xfa.host.openList(@object)
xfa.host.openList(@string) -- deprecated since XFA 2.6</code></pre>
<p>where @object is a reference to the drop down list field and @string is the SOM expression of the drop down list field.</p>
<pre><code>xfa.host.openList(myDropDownList); // set focus/show the drop list</code></pre>
<p>The second form of the API has been deprecated since XFA 2.6 which means that since Designer 8.1, it is preferred to use the first form which takes a reference to the field rather than its SOM expression.</p>
<p>If you&#8217;re using Designer 8.0 or earlier, you can get the SOM expression of any field by using its <em>somExpression</em> property:</p>
<pre><code>xfa.host.openList(ddlInDesigner71.somExpression)</code></pre>
<p>This works in both JavaScript and FormCalc with the same syntax.</p>
<p>Now if only there was a way to programmatically show the drop calendar of a date/time field&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2010/05/31/show-the-list-of-a-drop-down-list/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Acrobat JavaScript Debugger on XFA Forms</title>
		<link>http://forms.stefcameron.com/2010/03/12/acrobat-javascript-debugger-on-xfa-forms/</link>
		<comments>http://forms.stefcameron.com/2010/03/12/acrobat-javascript-debugger-on-xfa-forms/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 17:14:30 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Acrobat]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/?p=526</guid>
		<description><![CDATA[Many of you have been requesting some debugging features for XFA Forms (and I&#8217;m sure many more of you just haven&#8217;t voted for it yet). It so happens that Acrobat Pro has a JavaScript Debugger which can be used &#8212; to a limited extent &#8212; with XFA Forms. See John Brinkman&#8217;s post to learn more [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://forms.stefcameron.com/featur-o-meter/">Many of you</a> have been requesting some debugging features for XFA Forms (and I&#8217;m sure many more of you just haven&#8217;t voted for it yet). It so happens that Acrobat Pro has a <strong>JavaScript Debugger</strong> which can be used &#8212; to a <strong>limited</strong> extent &#8212; with XFA Forms. See <a href="http://blogs.adobe.com/formfeed/2010/03/using_the_acrobat_javascript_d.html">John Brinkman&#8217;s post</a> to learn more about it &#8212; thanks John!</p>
<p>As he puts it, <strong>there are limitations</strong>, the biggest ones of them being, in my opinion, the inability to debug script objects and the inability to retain breakpoints between debugging sessions. Nonetheless, this tool can give you way more insight than the good old &#8220;<a href="http://forms.stefcameron.com/2006/05/05/debugging-scripts/">JavaScript Console</a> + <a href="http://forms.stefcameron.com/2009/08/19/tip-pretty-xml-strings/">saveXML(&#8216;pretty&#8217;)</a>&#8221; combination can in certain cases, and it does it in a nice tree to boot!</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2010/03/12/acrobat-javascript-debugger-on-xfa-forms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tech Talk on Database Connected Forms</title>
		<link>http://forms.stefcameron.com/2010/03/10/tech-talk-on-database-connected-forms/</link>
		<comments>http://forms.stefcameron.com/2010/03/10/tech-talk-on-database-connected-forms/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 09:46:15 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Acrobat]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Designer]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/?p=522</guid>
		<description><![CDATA[Paul Guerette, a colleague of mine at Adobe, will be giving a &#8220;tech talk&#8221; eSeminar on connecting forms to databases over at AcrobatUsers.com on Tuesday, March 23, 2010, at 10am PST (1pm EST). If you have been struggling with connecting a form to a database, are wanting to know what the best practices and/or security [...]]]></description>
			<content:encoded><![CDATA[<p>Paul Guerette, a colleague of mine at <a href="http://adobe.com/">Adobe</a>, will be giving a &#8220;tech talk&#8221; eSeminar on <a href="http://www.acrobatusers.com/events/2220/tech-talk-database-connected-forms">connecting forms to databases</a> over at <a href="http://acrobatusers.com/">AcrobatUsers.com</a> on Tuesday, March 23, 2010, at 10am PST (1pm EST).</p>
<p>If you have been struggling with connecting a form to a database, are wanting to know what the best practices and/or security concerns are, or have some specific questions you would like to ask, I highly recommend you attend the session. It&#8217;s <strong>free</strong> to attend (and free to become a member in order to attend)!</p>
<p>I&#8217;ll be answering chat questions &#8220;live&#8221; as the session unfolds. I hope you can join us!</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2010/03/10/tech-talk-on-database-connected-forms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Disabling All Fields Within a Subform</title>
		<link>http://forms.stefcameron.com/2010/03/08/disabling-all-fields-within-subform/</link>
		<comments>http://forms.stefcameron.com/2010/03/08/disabling-all-fields-within-subform/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 02:27:29 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/?p=513</guid>
		<description><![CDATA[I thought I would point-out a nice improvement that was made to XFA &#60;subform&#62; elements back in XFA 2.8: The addition of the access property. In days of yore, if you wanted to disable all fields and exclusion groups (for the sake of brevity, I&#8217;ll refer to these collectively as &#8220;fields&#8221; in this article) in [...]]]></description>
			<content:encoded><![CDATA[<p>I thought I would point-out a nice improvement that was made to XFA &lt;subform&gt; elements back in <a href="http://partners.adobe.com/public/developer/xml/index_arch.html#xfa_28">XFA 2.8</a>: The addition of the <em>access</em> property.</p>
<p>In days of yore, if you wanted to disable all fields and exclusion groups (for the sake of brevity, I&#8217;ll refer to these collectively as &#8220;<em>fields</em>&#8221; in this article) in a particular section of your form, you would&#8217;ve had to write a script that recursively drilled down into all children of that section looking for <em>fields</em> to disable. This is because the access attribute only applied to <em>fields</em>.</p>
<p>With this change, assuming the section in question is contained within a subform, you can now easily disable all <em>fields </em>contained within it simply by setting the <strong>subform</strong>&#8216;s <strong>access attribute</strong> to &#8220;readOnly&#8221;!</p>
<p><span id="more-513"></span>
<p>The following table describes the four levels of restrictiveness (in XFA 2.8, from the highest level to the lowest) that can be imposed on <em>fields</em> using the access attribute, either directly on a <em>field</em> or by a parent subform:</p>
<table border="1" cellspacing="0" cellpadding="4" style="margin-bottom: 18px">
<tbody>
<tr>
<td><strong>Level</strong></td>
<td><strong>Access Value<br />
</strong></td>
<td><strong>Effect</strong></td>
</tr>
<tr>
<td>1</td>
<td><code>nonInteractive</code></td>
<td>Value can be loaded and calculations performed only upon form initialization.</td>
</tr>
<tr>
<td>2</td>
<td><code>protected</code></td>
<td>The user cannot change the value directly and the <em>field</em> does not participate in the tabbing sequence. The <em>field</em> does not generate any events.</td>
</tr>
<tr>
<td>3</td>
<td><code>readOnly</code></td>
<td>While the user may not change the value directly, it may be altered via scripts. The <em>field</em> still participates in the tabbing sequence and all events are generated except those related to direct user interaction.</td>
</tr>
<tr>
<td>4</td>
<td><code>open</code> (default)</td>
<td>The <em>field</em> is fully interactive and responds to direct user interaction.</td>
</tr>
</tbody>
</table>
<p>When a subform imposes restrictions on the <em>fields</em> it contains (meaning all <em>fields</em> within any level of nesting, not just immediate children), the inheritance on child <em>fields</em> and subforms follows that of the most restrictive parent imposition. For example, if a subform imposes access=&#8221;protected&#8221; and a child subform has access=&#8221;readOnly&#8221;, all of the inner subform&#8217;s children, including the inner subform itself, will effectively have a &#8220;protected&#8221; access level.</p>
<p>The explanations of the various access types in the table above are summarized. &#8220;Access Restrictions&#8221; on page 48 of the <a href="http://partners.adobe.com/public/developer/xml/index_arch.html#xfa_28">XFA 2.8 specification</a> has more precise, albeit more technical, explanations of each level of restrictiveness.</p>
<h2>Setting Access by Script</h2>
<p>Setting the access attribute of a <em>field</em> or subform by script is simple, both in JavaScript and FormCalc:</p>
<pre><code>// set access level to read-only:
FormObject.access = "readOnly";</code></pre>
<p>If you wanted to disable all <em>fields </em>in the entire form with a <strong>single line of script</strong>, you would simply set the root subform&#8217;s access attribute to something other than &#8220;open&#8221;, as appropriate:</p>
<pre><code>// if the root subform's name is "form1":
xfa.form.form1.access = "nonInteractive"</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2010/03/08/disabling-all-fields-within-subform/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PDF Forms Bible Review</title>
		<link>http://forms.stefcameron.com/2009/11/13/pdf-forms-bible-review/</link>
		<comments>http://forms.stefcameron.com/2009/11/13/pdf-forms-bible-review/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 23:13:18 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Acrobat]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Designer]]></category>
		<category><![CDATA[Instance Manager]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tables]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/2009/11/13/pdf-forms-bible-review/</guid>
		<description><![CDATA[Last February, I announced the release of a new Designer book titled, &#8220;PDF Forms Using Acrobat and LiveCycle Designer Bible&#8221;. Over the past few months, I had the opportunity to review it and I thought I would share my comments, with respect to the second-half of the book, which deals with LiveCycle Designer ES and [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: left; margin-right: 15px" alt="PDF Forms Using Acrobat and LiveCycle Designer Bible" src="http://forms.stefcameron.com/images/pdfforms-book-cover.jpg">
<p>Last February, I announced the release of a <a href="http://forms.stefcameron.com/2009/02/05/new-book-acrobat-and-designer-bible/">new Designer book</a> titled, &#8220;PDF Forms Using Acrobat and LiveCycle Designer Bible&#8221;.</p>
<p>Over the past few months, I had the opportunity to review it and I thought I would share my comments, <strong>with respect to the second-half of the book</strong>, which deals with LiveCycle Designer ES and XFA forms, to help you decide if it would be a good book for you*. (The first-half deals with authoring PDF forms, a.k.a. AcroForms, in Acrobat and is beyond the scope of my blog.)</p>
<div style="clear: both; display: block">
<p><strong>Pros:</strong></p>
<ul>
<li>explains the licensing agreement involved when enabling forms for Reader using Acrobat&#8217;s &#8220;Extend Features in Adobe Reader&#8221; feature (p. 268) &#8212; this is a frequently-used feature however its governing licensing agreement, seldom understood, is explained here in &#8220;plain English&#8221;;
<li>presents and reasons through different design approaches for a particular solution, helping the reader make an informed decision on the best course of action;
<li>anything and everything you could possibly want to know is dealt with in some way;
<li>lots of important, time-saving insights in the inline &#8216;notes&#8217;;
<li>something for everyone from beginner to advanced;
<li>many cross-references between various topics, making it very easy to start in any chapter and still find all the information you need.</li>
</ul>
<p><strong>Caution:</strong></p>
<ul>
<li>risk of &#8220;information overload&#8221; &#8212; use this book as <em>reference</em> since it&#8217;s not a light read, though their goal is simply to present a myriad of options and let you pick the one that best suits your needs.</li>
</ul>
<p><strong>Overview of Topics Covered:</strong></p>
<ul>
<li>all about tables (from simple layouts to advanced);
<li>data merging with bindings;
<li>Designer user interface details and lots of tips and tricks for accelerating form layout tasks;
<li>working with static forms (with PDF backgrounds) and dynamic forms, highlighting the differences;
<li>great details on all sorts of pagination options;
<li>lots of detail on JavaScript and FormCalc, good scripting exercises with explanations, debugging tips, table with JavaScript and equivalent FormCalc functions to make it easy to script in either language if the other is more familiar to you;
<li>form deployment options;
<li>when and how to use data connections in your forms (XML, schema, database, web service) and setting data bindings;
<li>great overview of LiveCycle ES, its components (e.g. LC Forms, LC Reader Extensions, LC Rights Management, LC Content Services, etc.) and what they do.</li>
</ul>
<p>This book is available now on <a href="http://www.amazon.com/Forms-Using-Acrobatand-LiveCycle-Designer/dp/047040017X">Amazon.com</a> and <a href="http://www.wiley.com/WileyCDA/WileyTitle/productCd-047040017X.html">Wiley.com</a> and <a href="http://www.google.ca/search?q=pdf+forms+bible">elsewhere</a>.</p>
<p style="font-size: 9px">* Please note that these opinions are not necessarily those of Adobe Systems Incorporated.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2009/11/13/pdf-forms-bible-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Designer ES2 Scripting Reference</title>
		<link>http://forms.stefcameron.com/2009/11/12/designer-es2-scripting-reference/</link>
		<comments>http://forms.stefcameron.com/2009/11/12/designer-es2-scripting-reference/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 03:25:18 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Designer]]></category>
		<category><![CDATA[LiveCycle]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/?p=470</guid>
		<description><![CDATA[This is one of the references I find the most useful when writing scripts and it&#8217;s now available for Designer ES2. What&#8217;s more, you can now find all of the ES2 Developer and Programmer documentation all in a single place just like all ES2 documentation (which includes the Dev and Prog docs from the former [...]]]></description>
			<content:encoded><![CDATA[<p>This is one of the references I find the most useful when writing scripts and it&#8217;s <a href="http://www.adobe.com/go/learn_lc_scriptingReference_9">now available</a> for Designer ES2.</p>
<p>What&#8217;s more, you can now find all of the ES2 Developer and Programmer documentation all in a <a href="http://www.adobe.com/go/learn_lc_dp_list_9">single place</a> just like <a href="http://www.adobe.com/go/learn_lc_doclist_9">all ES2 documentation</a> (which includes the Dev and Prog docs from the former link). Great sites to bookmark and nice to finally have it all in one spot!</p>
<p>This all comes to you due to the recent <a href="http://www.adobe.com/devnet/livecycle/">LiveCycle Developer Center</a> site refresh in conjunction with the recent release of <a href="http://forms.stefcameron.com/2009/11/06/livecycle-es2-ships/">LiveCycle ES2</a>. Check it out!</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2009/11/12/designer-es2-scripting-reference/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multi-Selection List Schema Definition</title>
		<link>http://forms.stefcameron.com/2009/09/30/multi-selection-list-schema-definition/</link>
		<comments>http://forms.stefcameron.com/2009/09/30/multi-selection-list-schema-definition/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 14:07:02 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Acrobat]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/2009/09/30/multi-selection-list-box-schema-definition/</guid>
		<description><![CDATA[After spending some time, recently, showing you how to connect your form to a schema and highlighting Designer&#8217;s support for schema metadata, I thought I would round-off my current train of thought on schemas by tackling multi-selection listboxes. Since they store their selected data in &#60;value&#62; nodes, once you think about it, their schema definition [...]]]></description>
			<content:encoded><![CDATA[<p>After spending some time, recently, showing you how to <a href="http://forms.stefcameron.com/2009/08/03/connecting-to-a-schema/">connect your form to a schema</a> and highlighting Designer&#8217;s support for <a href="http://forms.stefcameron.com/2009/08/28/schema-metadata/">schema metadata</a>, I thought I would round-off my current train of thought on schemas by tackling multi-selection listboxes. Since they store their selected data in &lt;value&gt; nodes, once you think about it, their schema definition may not be obvious. When you&#8217;re working with XML data that isn&#8217;t governed by a schema and namespaces, it is perhaps easier to work with (i.e. accept) these &lt;value&gt; nodes however things change when you have a schema telling you how your data must be structured and scoped (with namespaces).</p>
<p><span id="more-449"></span><br />
<h2>How Lists Store Selected Items</h2>
<p>To better understand the challenges, let&#8217;s look at how list form objects store a multi-selection of values.</p>
<p>In the <strong>Form DOM</strong>, the list&#8217;s value actually contains XML rather than plain text. For example, say we have a multi-selection list named &#8220;ListBox1&#8243; (bound to a data element named &#8220;list1&#8243;) with items (&#8220;item1&#8243;, &#8220;item2&#8243;, &#8220;item3&#8243;). If the first two items were selected, the list&#8217;s value would look like this:</p>
<pre><code>&lt;value&gt;
    &lt;exData contentType="text/xml"&gt;
        &lt;list1&gt;
            &lt;value&gt;item1&lt;/value&gt;
            &lt;value&gt;item2&lt;/value&gt;
        &lt;/list1&gt;
    &lt;/exData&gt;
&lt;/value&gt;</code></pre>
<p>In <strong>script</strong>, this would translate to a newline (\n)-delimited string when the list&#8217;s value is accessed from its rawValue property:</p>
<pre><code>item1\nitem2</code></pre>
<p>In the <strong>Data DOM</strong>, the list&#8217;s value is stored in a series of repeating &lt;value&gt; nodes, much like the way it is stored in the Form DOM:</p>
<pre><code>&lt;list1&gt;
    &lt;value&gt;item1&lt;/value&gt;
    &lt;value&gt;item2&lt;/value&gt;
&lt;/list1&gt;</code></pre>
<h2>Adding the Schema</h2>
<p>A schema describes how XML should be structured. Given how lists store their selected items in data, a schema that includes a multi-selection list will need to allow for the element that defines the list to contain zero or more repeating &lt;value&gt; nodes. Unfortunately, this means modifying your schema, if you already have one. (I can think of at least one workaround to this which would involve script and a sibling, hidden text field bound to the element in your schema, as opposed to the list itself, in which you would store the selection, but I won&#8217;t get into that in this article.)</p>
<p>For example, <a href="http://forms.stefcameron.com/samples/data-binding/schema-multisellist/multiSelList-schema.xsd">this</a> is a schema that defines a &#8220;form1&#8243; root element that contains an element named &#8220;list1&#8243; that has a multi-selection list type (the way XFA expects it).</p>
<h3>Data Connection</h3>
<p>The problem with this structure is that once you connect your form to this schema, the Data View connection tree will interpret the list1 element as being a subform that contains a repeating node, &#8220;value&#8221;:</p>
<p><img src="http://forms.stefcameron.com/images/SchemaMultiSelList/SchemaMultiSelList-1.jpg"> </p>
<p>Because of this interpretation, you cannot simply drag &amp; drop the &#8220;list1&#8243; schema element into your form in order to get a multi-selection list. Instead, you&#8217;ll get a subform with a text field inside of it instead (only an element with a simple type restricted to an enumeration of values would be interpreted as a list). Furthermore, you cannot use the picker widget next to the &#8220;Object palette &gt; Binding tab &gt; Data Binding property&#8221; to assign &#8220;list1&#8243; to a listbox you have already dragged into your form from the Object Library palette because &#8220;list1&#8243; is viewed as a container (subform) and the form object you are attempting to bind is a field.</p>
<h3>Data Binding</h3>
<p>In order to bind the listbox to the &#8220;list1&#8243; schema element, you must manually type its binding expression into the &#8220;Object palette &gt; Binding tab &gt; Data Binding property&#8221;. For our simple use case, <strong>the binding is &#8220;list1&#8243;</strong>. Note that you don&#8217;t actually bind the repeating &#8220;value&#8221; element to anything and that the schema data connection tree will not actually indicate that the &#8220;list1&#8243; element is bound to a form object even though it now is (I&#8217;m guessing this is because it is expecting &#8220;list1&#8243; to be bound to a subform, not a field).</p>
<p>The result of binding the listbox to the &#8220;list1&#8243; schema element is that the Form DOM output changes slightly to include the proper namespace on the bound element within the field&#8217;s value:</p>
<pre><code>&lt;value&gt;
    &lt;exData contentType="text/xml"&gt;
        &lt;scof:list1 xmlns:scof="http://forms.stefcameron.com/ns/2009/"&gt;
            &lt;value&gt;item1&lt;/value&gt;
            &lt;value&gt;item2&lt;/value&gt;
        &lt;/scof:list1&gt;
    &lt;/exData&gt;
&lt;/value&gt;</code></pre>
<h2>Submitting Data</h2>
<p>As you might expect, given the structure of the listbox&#8217;s selection in the Form DOM above, the list&#8217;s selection data will be similar in the Data DOM (which is what would be submitted from the form as well):</p>
<pre><code>&lt;xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"&gt;
    &lt;scof:form1 xmlns:scof="http://forms.stefcameron.com/ns/2009/"&gt;
        &lt;scof:list1&gt;
            &lt;value&gt;item1&lt;/value&gt;
            &lt;value&gt;item2&lt;/value&gt;
        &lt;/scof:list1&gt;
    &lt;/scof:form1&gt;
&lt;/xfa:data&gt;</code></pre>
<p>The only problem with the data above is that it isn&#8217;t valid against the schema which specifies that the repeating &lt;value&gt; nodes inside the list1 element are part of the &#8220;scof&#8221; (target) namespace and should therefore look like &lt;scof:value&gt;.</p>
<h2>Submitting Namespaced Data</h2>
<p>In order to get the namespace into the repeating &lt;value&gt; nodes for the selected values, we have to use a workaround that involves a little script in the listbox&#8217;s Exit event (though the script could be triggered elsewhere, if you like):</p>
<pre><code>// JavaScript:

// schema namespace info
var nspace = "scof";
var nsUri = "http://forms.stefcameron.com/ns/2009/";

// get selection from list
var selection = this.rawValue.split("\n");

// build XML string for new selection in *Form DOM*
//  that includes the namespace in the &lt;value&gt;
//  nodes the outer &lt;listSelection&gt; node is
//  essentially irrelevant and will be discarded later
//  however it is required so that we can load its
//  content into the listbox's exData value node where
//  its value is set in the Form DOM
// this.dataNode.name gets the listbox's bound data
//  element name from the Data DOM which is required
//  in the XML
var newSelection = "&lt;listSelection&gt;\n&lt;" + nspace +
    ":" + this.dataNode.name + " xmlns:" + nspace +
    "='" + nsUri + "'&gt;";

// add selected items into the new selection -- take
//  note of the newline character at the beginning of
//  the string as it is critical to the XML loading
//  properly later on (it shouldn't be but it is...)
for (var i = 0; i &lt; selection.length; i++)
{
    newSelection += "\n&lt;" + nspace + ":value&gt;" +
        selection[i] + "&lt;/" + nspace + ":value&gt;";
}

// close the XML elements in the string
newSelection += "\n&lt;/" + nspace + ":" +
    this.dataNode.name + "&gt;\n&lt;/listSelection&gt;";

// load the new namespaced selection into the listbox's
//  exData value node, ignoring the root &lt;listSelection&gt;
//  node in the XML string
this.value.exData.loadXML(newSelection, true, true);</code></pre>
<p>The script above essentially builds an XML string equivalent in structure to that which is normally used to store the list&#8217;s selection in the Form DOM however it adds the necessary namespaces to the repeating &lt;ns:value&gt; nodes. This change is then replicated in the list1 data node in the Data DOM and the form&#8217;s exported data changes to this (which can be successfully validated against the schema we&#8217;re using):</p>
<pre><code>&lt;xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"&gt;
    &lt;scof:form1 xmlns:scof="http://forms.stefcameron.com/ns/2009/"&gt;
        &lt;scof:list1&gt;
            &lt;scof:value&gt;item1&lt;/scof:value&gt;
            &lt;scof:value&gt;item2&lt;/scof:value&gt;
        &lt;/scof:list1&gt;
    &lt;/scof:form1&gt;
&lt;/xfa:data&gt;</code></pre>
<h3><a name="warning"></a>Import Data Warning</h3>
<p>Unfortunately, I have to point-out a bug as it relates to exporting multi-selection values with namespaces (which you only get when you use the above workaround script): Importing data with namespaced &lt;ns:value&gt; nodes for multi-selection lists &#8212; though valid XML and valid against the schema &#8212; will fail in Acrobat 9.1.3 (I have not done any testing on previous versions). My testing has revealed that the form doesn&#8217;t render properly after the data merge. Importing namespaced data that does not have namespaced &lt;value&gt; nodes for multi-selection lists, however, does work fine (this is the default way data is exported, unless you use the script I outlined above).</p>
<h2>Sample Form</h2>
<p>I have built a sample form that demonstrates how multi-selection lists store their data in the Form DOM and Data DOM. The form also includes a checkbox which, when checked, will generate namespaced &lt;ns:value&gt; nodes instead of the default &lt;value&gt; nodes, using the workaround script in the list&#8217;s Exit event.</p>
<p>Download:</p>
<ul>
<li><a href="http://forms.stefcameron.com/samples/data-binding/schema-multisellist/SchemaMultiSelList.pdf">Form [pdf]</a>
<li><a href="http://forms.stefcameron.com/samples/data-binding/schema-multisellist/multiSelList-schema.xsd">Schema [xsd]</a>
<li><a href="http://forms.stefcameron.com/samples/data-binding/schema-multisellist/sampleData.xml">Sample Data [xml]</a>
<li><a href="http://forms.stefcameron.com/samples/data-binding/schema-multisellist/sampleData-ns.xml">Sample Data (namespaced) [xml]</a></li>
</ul>
<p><strong>Minimum Requirements:</strong> I designed this form using Designer ES2 Beta and Acrobat 9.1.3 however the form should work all the way back to Designer 7.1 and Acrobat 7.0.5.</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2009/09/30/multi-selection-list-schema-definition/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Schema Metadata</title>
		<link>http://forms.stefcameron.com/2009/08/28/schema-metadata/</link>
		<comments>http://forms.stefcameron.com/2009/08/28/schema-metadata/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 03:48:35 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Data Binding]]></category>
		<category><![CDATA[Designer]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[XFA]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/2009/08/28/schema-metadata/</guid>
		<description><![CDATA[My first tutorial on XML schemas explained how to connect your form to a schema however it did not show some of the Data View palette&#8217;s special features with respect to metadata in XML schemas. Using metadata based on a combination of the XML Schema appInfo and Dublin Core title and description elements, you can [...]]]></description>
			<content:encoded><![CDATA[<p>My first tutorial on XML schemas explained how to <a href="http://forms.stefcameron.com/2009/08/03/connecting-to-a-schema/">connect your form to a schema</a> however it did not show some of the Data View palette&#8217;s special features with respect to metadata in XML schemas.</p>
<p>Using metadata based on a combination of the XML Schema <a href="http://www.w3.org/TR/xmlschema-1/#element-appinfo">appInfo</a> and Dublin Core <a href="http://dublincore.org/documents/2008/01/14/dcmi-terms/#elements-title">title</a> and <a href="http://dublincore.org/documents/2008/01/14/dcmi-terms/#elements-description">description</a> elements, you can influence how the Data Connection Wizard creates fields you drag and drop from the data connection tree into your form. You can also direct the Data View palette to show some of this information in the Schema Data Connection Tree that it displays.</p>
<p><span id="more-428"></span>
<p>To demonstrate these features, I have <a href="http://forms.stefcameron.com/samples/data-binding/schema/movieRental-meta.xsd">extended</a> the <a href="http://forms.stefcameron.com/samples/data-binding/schema/movieRental.xsd">original</a> movie rental schema by adding metadata to its schema elements.<br />
<h2>Element Descriptions</h2>
<p>Sometimes a schema element&#8217;s purpose or use isn&#8217;t immediately clear based on its name and/or other properties. For example, just by seeing that the schema has a &#8220;customer.account&#8221; element wouldn&#8217;t necessarily tell you that this element should be empty for a new customer (since the system would generate a new account number upon submission of the customer&#8217;s first movie rental order). To clarify the use of this element, a description can be provided:</p>
<pre><code>&lt;xs:element name="account" type="xs:string" minOccurs="0"&gt;
    &lt;xs:annotation&gt;
        &lt;xs:appinfo&gt;
            &lt;dc:description&gt;
                Customer's account number (empty if it's a new customer).
            &lt;/dc:description&gt;
        &lt;/xs:appinfo&gt;
    &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</code></pre>
<p>Using the &#8220;Data View palette &gt; Palette menu button <img style="display: inline" src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-6.jpg"> &gt; &#8216;Show Both&#8217; command&#8221;, you can see the &lt;dc:description&gt; metadata associated with elements in your schema right within the Data Connection Tree:</p>
<p><img src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-1.jpg"> </p>
<p>Note that the description element must be part of the Dublin Core namespace (xmlns:dc=http://purl.org/dc/elements/1.1/) and must be contained within the XML Schema //annotation/appInfo elements in order for the Data Connection Wizard to detect it.</p>
<h2>Form Object Captions</h2>
<p>Often times schemas are defined at a corporate level because they can represent business rules and describe how data must be structured for its systems to be able to interpret it correctly. In those cases, it may be useful to also influence/dictate the labels that should be used to identify fields associated to certain schema elements. This can also be achieved with metadata by specifying title information:</p>
<pre><code>&lt;xs:element name="account" type="xs:string" minOccurs="0"&gt;
    &lt;xs:annotation&gt;
        &lt;xs:appinfo&gt;
            &lt;dc:title&gt;Account #:&lt;/dc:title&gt;
        &lt;/xs:appinfo&gt;
    &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</code></pre>
<p>Unlike descriptive metadata, this information is not displayed in the Data Connection Tree. Instead, it is used by the Data Connection Wizard when you drag and drop a schema element from the Data Connection Tree into your form.</p>
<p>Remember that, in the original schema (that didn&#8217;t have any metadata), generated fields would get captions similar to their schema element names. For example,&nbsp; dragging the &#8220;customer.account&#8221; field into a form would produce a field with &#8220;Account&#8221; as its caption. With the title metadata as defined above, the generated caption would instead be &#8220;Account #:&#8221;, as in the image below:</p>
<p><img src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-2.jpg"> </p>
<p>Note that the title element must be part of the Dublin Core namespace (xmlns:dc=http://purl.org/dc/elements/1.1/) and must be contained within the XML Schema //annotation/appInfo elements in order for the Data Connection Wizard to detect it.</p>
<h2>Extra Descriptive Information</h2>
<p>There&#8217;s one more way to provide information related to an element in a schema: Any text that is directly specified within an XML Schema //annotation/appInfo element (and is <strong>not</strong> further contained within a Dublin Core title or description element) is interpreted as extra &#8220;descriptive information&#8221;. When the element is dragged and dropped into a form, this text will be imported and associated with the generated field within a &lt;desc&gt; node, <em>provided the &#8220;Generate Descriptive Information&#8221; option is checked</em> in the &#8220;Data View palette &gt; Palette menu button <img style="display: inline" src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-6.jpg"> &gt; Options dialog&#8221;:</p>
<p><img src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-3.jpg"> </p>
<p>For example, the &#8220;returnBy&#8221; schema element is defined as follows:</p>
<pre><code>&lt;xs:element name="returnBy" type="xs:date"&gt;
    &lt;xs:annotation&gt;
        ...
        &lt;xs:appinfo&gt;
            Movies must be returned by 11:59pm on this date.
        &lt;/xs:appinfo&gt;
        &lt;xs:appinfo&gt;
            The late fee is is $0.50/hour.
        &lt;/xs:appinfo&gt;
    &lt;/xs:annotation&gt;
&lt;/xs:element&gt;</code></pre>
<p>Dragging and dropping that element into your form would produce the following field mark-up in the XML Source view:</p>
<pre><code>&lt;field name="returnBy"&gt;
    ...
    &lt;desc&gt;
        &lt;text name="Schema Annotation"&gt;
            Movies must be returned by 11:59pm on this date.
        &lt;/text&gt;
        &lt;text name="Schema Annotation 2"&gt;
            The late fee is is $0.50/hour.
        &lt;/text&gt;
    &lt;/desc&gt;
&lt;/field&gt;</code></pre>
<p>The Info palette could then be used to view the contents of all nodes inside the selected field&#8217;s &lt;desc&gt; node:</p>
<p><img src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-4.jpg"> </p>
<p>You can associate any number of extra &#8220;descriptive information&#8221; metadata elements to a single schema element definition. Each one would be imported as a separate &lt;text name=&#8221;Schema Annotation {x}&#8221;&gt; node within the associated form object&#8217;s &lt;desc&gt; node</p>
<p>This information can also be viewed within the Data View palette by choosing the &#8220;Palette menu button <img style="display: inline" src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-6.jpg"> &gt; &#8216;Show Info&#8217; command&#8221;. This will display the Info Panel in the bottom half of the palette. Selecting the &#8220;returnBy&#8221; schema element would then display the following information:</p>
<ul>
<li>XFA object name (returnBy);
<li>associated XFA object type (date/time field, since the schema defines its type as &#8220;date&#8221;);
<li>occurrence (single since it isn&#8217;t repeatable like the &#8220;movie&#8221; element, for example); and
<li>all other metadata identified as &#8220;descriptive info&#8221; associated to the element.</li>
</ul>
<p><img src="http://forms.stefcameron.com/images/SchemaMetadata/SchemaMetadata-5.jpg"> </p>
<h3>Script Access</h3>
<p>Finally, the descriptive information found in a form object&#8217;s //desc/text nodes can be retrieved via script by accessing its &#8220;desc&#8221; node property and iterating through all child nodes that are of type &#8220;text&#8221; and have &#8220;Schema Annotation&#8221; in their name.</p>
<p>For example, to output the two descriptions in the &#8220;returnBy&#8221; field (as defined above) to the <a href="http://forms.stefcameron.com/2006/05/05/debugging-scripts/">JavaScript Console</a> in Acrobat, you could use the following script:</p>
<pre><code>// JavaScript:
var descList = returnBy.desc.nodes;
for (var i = 0; i &lt; descList.length; i++)
{
    var item = descList.item(i);
    if (item.className == "text" &amp;&amp; item.name &amp;&amp;
            item.name.indexOf("Schema Annotation") == 0)
    {
        console.println(item.value);
    }
}</code></pre>
<p>With a little more effort, you could parse-out all sorts of useful information provided by this type of metadata in your schemas though, most of the time, that information can usually be expressed in real schema mark-up (e.g. list items and values).</p>
<h2>Combinations</h2>
<p>Of course, you aren&#8217;t limited to using a single type of metadata on a given schema element: You can combine them to provide the degree of information you require for any element. For example, the &#8220;customer.account&#8221; element specifies both title and description metadata while the &#8220;returnBy&#8221; element specifies title and descriptive information metadata.</p>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2009/08/28/schema-metadata/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Tip: Pretty XML Strings</title>
		<link>http://forms.stefcameron.com/2009/08/19/tip-pretty-xml-strings/</link>
		<comments>http://forms.stefcameron.com/2009/08/19/tip-pretty-xml-strings/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 12:50:21 +0000</pubDate>
		<dc:creator>Stefan Cameron</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://forms.stefcameron.com/2009/08/19/tip-pretty-xml-strings/</guid>
		<description><![CDATA[I regularly use the saveXML() method, available on all node class-based objects, as a way to debug my forms (think of it as a type of introspection technique). The method outputs a string representation of the XML content of the node in question, which helps when attempting to discover the underlying object structure without a [...]]]></description>
			<content:encoded><![CDATA[<p>I regularly use the saveXML() method, available on all node class-based objects, as a way to debug my forms (think of it as a type of introspection technique). The method outputs a string representation of the XML content of the node in question, which helps when attempting to discover the underlying object structure without a debugger&#8230;</p>
<p>For example, say you have a simple form with a text field and a numeric field. The following statement will output the form&#8217;s data to the JavaScript Console in Acrobat:</p>
<pre><code>console.println(xfa.datasets.data.saveXML());</code></pre>
<p>The result, however, isn&#8217;t very readable:</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"
&gt;&lt;form1
&gt;&lt;TextField1
&gt;asdf&lt;/TextField1
&gt;&lt;NumericField1
&gt;1234&lt;/NumericField1
&gt;&lt;/form1
&gt;&lt;/xfa:data
&gt;</code></pre>
<p>Though I had been using saveXML() for quite some time, I hadn&#8217;t realized that it actually takes an optional parameter, a string with a value of &#8220;pretty&#8221;, that results in much nicer output.</p>
<pre><code>console.println(xfa.datasets.data.saveXML('pretty'));</code></pre>
<p>results in the following pretty/readable output:</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"&gt;
&nbsp;&nbsp;&nbsp;&lt;form1&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;TextField1&gt;asdf&lt;/TextField1&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;NumericField1&gt;1234&lt;/NumericField1&gt;
&nbsp;&nbsp;&nbsp;&lt;/form1&gt;
&lt;/xfa:data&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://forms.stefcameron.com/2009/08/19/tip-pretty-xml-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

