<?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>Jens Arps &#187; dijit</title>
	<atom:link href="http://jensarps.de/tag/dijit/feed/" rel="self" type="application/rss+xml" />
	<link>http://jensarps.de</link>
	<description></description>
	<lastBuildDate>Fri, 25 Nov 2011 16:16:34 +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>A collapsible fieldset as dojo widget</title>
		<link>http://jensarps.de/2009/10/16/a-collapsible-fieldset-as-dojo-widget/</link>
		<comments>http://jensarps.de/2009/10/16/a-collapsible-fieldset-as-dojo-widget/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 18:43:01 +0000</pubDate>
		<dc:creator>Jens Arps</dc:creator>
				<category><![CDATA[Dojo Love]]></category>
		<category><![CDATA[Goodies to go]]></category>
		<category><![CDATA[dijit]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[widget]]></category>

		<guid isPermaLink="false">http://jensarps.de/?p=59</guid>
		<description><![CDATA[Though many people would disagree, I for one like to use fieldsets to structure complex forms. Even better do I like fieldsets that are collapsible. As there is no such fieldset with dojo, I decided to write my own widget. While doing so, I learnt an interesting lesson… First, I wrote it pretty simple, inheriting [...]]]></description>
			<content:encoded><![CDATA[<p>Though many people would disagree, I for one like to use fieldsets to structure complex forms. Even better do I like fieldsets that are collapsible.</p>
<p>As there is no such fieldset with dojo, I decided to write my own widget. While doing so, I learnt an interesting lesson…</p>
<p>First, I wrote it pretty simple, inheriting the widget from dijit._Widget and dijit._Templated. It had a toggle button next to its legend, which could be clicked. The toggle was a simple display none/block change.<br />
<span id="more-59"></span><br />
But I wanted it to be accessible via the keyboard – so I added a tabIndex and a key handler. Next, I wanted it to be able to hold and parse widgets, so I inherited it from dijit.layout.ContentPane so I could make use of the content setter. Then I wanted it to animate smoothly, so I added animations, and so on… You get the point, I guess. Well, this went on for a while, until I made an unpleasant discovery: My fieldset was almost a clone of dijit.TitlePane. Ugh.</p>
<p><em>I had put all the time into creating a copy of something, that already existed.</em></p>
<p>So I inherited the fieldset widget from dijit.TitlePane and ended up with less than 50 lines of code. And it was a matter of minutes to do so. Ok, lesson learned: If you need something that doesn&#8217;t exist and you are going to code it – first check if there&#8217;s something that behaves similar to what you want. Or similar to what you <em>might want in the future</em>. If I had invested a little more time in thinking about the fieldset widget before starting to code, it would have been obvious that I wanted the above mentioned features one day. And I would have saved a lot of time.</p>
<p>Well, however, here it is: a collapsible fieldset, coming with all the ContentPane goodness (child widgets, remote loading,…).</p>
<p>You can create it via markup (I put it into a namespace called &#8220;app&#8221;; choose a namespace you like):</p>
<pre>&lt;fieldset dojotype="app.Fieldset"&gt;
    &lt;legend&gt;Legend&lt;/legend&gt;
    Content
&lt;/fieldset&gt;</pre>
<p>or programmatically:</p>
<pre>var fieldset = new app.Fieldset({legend:'dojo fieldset', id: 'someId'},dojo.create('div',{},dojo.body()));</pre>
<p>The fieldset takes pretty much the same arguments as dijit.TitlePane. To change the legend, use <code>dojo.attr('legend','Teh new legend')</code>, to change the content <code>dojo.attr('content',content)</code> as usual. To stay close to TitlePane, I left <code>_setTitleAttr()</code> in it, but it is an alias for <code>_setLegendAttr()</code>.</p>
<p>The code is simple (after I inherited from TitlePane), I only added a method to setup the legend tag and changed the methods that handle hover states, as the TitlePane&#8217;s methods paid no respect to the dijit&#8217;s base class. The fieldset is closed by default, but you can add <code>open="true"</code> to the markup (or add <code>open: true</code> to the constructor args) to make it start open. You can style it as you would style any other widget.</p>
<p>The testpage is over here: <a href="http://jensarps.de/tests/dojo_tests/test_Fieldset.html" target="_blank">test_Fieldset.html<br />
</a> Code: <a href="http://jensarps.de/tests/dojo_tests/dojo-1.3.2/app/Fieldset.js" target="_blank">Fieldset.js</a><br />
Template: <a href="http://jensarps.de/tests/dojo_tests/dojo-1.3.2/app/templates/Fieldset.html" target="_blank">Fieldset.html</a></p>
<p><strong>Update</strong>: If you have downloaded the code and intend to use it, please re-download it, as I updated a method and fixed a namespace confusion (and added doc).</p>
]]></content:encoded>
			<wfw:commentRss>http://jensarps.de/2009/10/16/a-collapsible-fieldset-as-dojo-widget/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

