<?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>uxebu » blog &#187; Forms</title>
	<atom:link href="http://uxebu.com/tag/forms/feed/" rel="self" type="application/rss+xml" />
	<link>http://uxebu.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 14:53:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Don&#8217;t send your data twice &#8211; a little widget</title>
		<link>http://uxebu.com/blog/2008/08/02/dont-send-your-data-twice-a-little-widget/</link>
		<comments>http://uxebu.com/blog/2008/08/02/dont-send-your-data-twice-a-little-widget/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 11:43:09 +0000</pubDate>
		<dc:creator>nonken</dc:creator>
				<category><![CDATA[dojo]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=41</guid>
		<description><![CDATA[How many times do we need to disable a button after sending a xhr call or submitting a form? Almost everytime, the element which induces a data transfer, should be disabled until you get a reply from the server. I&#8217;ve written a short and simple extension of the &#8220;dijit.form.Button&#8221; widget called &#8220;dojox.form.BusyButton&#8221;, which provides a [...]]]></description>
			<content:encoded><![CDATA[<p>How many times do we need to disable a button after sending a xhr call or submitting a form?<br />
Almost everytime, the element which induces a data transfer, should be disabled until you get a reply  from the server.</p>
<p>I&#8217;ve written a short and simple extension of the &#8220;dijit.form.Button&#8221; widget called &#8220;dojox.form.BusyButton&#8221;, which provides a simple API to let you deal with those cases when you don&#8217;t want to allow the user to hit the submit button a second time.<span id="more-41"></span><br />
<h4>Lets take a look at two examples</h4>
<style type="text/css">
@import url(/js/dojo/trunk/release/dojo/dijit/themes/nihilo/nihilo.css);
@import url(/js/dojo/trunk/release/dojo/dojox/form/resources/BusyButton.css);
.dijitBusyButtonIcon {
	width: 10px;
	height: 10px;
	vertical-align: middle;
	margin-left: 4px;
}</style>
<p><script type="text/javascript">
dojo.addOnLoad(function(){
dojo.query("body").addClass("nihilo");
});
dojo.require("dojox.form.BusyButton");</script>Button without timeout:<br />
<button dojotype="dojox.form.BusyButton" busylabel="Charging creditcard...">Pay the bill</button></p>
<p>Button with five second timeout:<br />
<button dojotype="dojox.form.BusyButton" timeout="5000" busylabel="Sending...">Send</button></p>
<p>You can find a few more examples at the <a href="http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/form/tests/test_BusyButton.html" target="_blank">Dojox test page</a>. There you will find a few special cases of how to use the widget.</p>
<h4>Download the code</h4>
<p>You can get the widget when downloading the latest nightly from <a href="http://archive.dojotoolkit.org/nightly/">http://archive.dojotoolkit.org/nightly/</a> or the upcoming 1.2 release.</p>
<h4>To include it on your page simply insert following code</h4>
<p>CSS:</p>
<p>Note that you also have to include the dijit theme CSS on your page. This can be either the tundra, nihilo, soria or a custom theme. In this example we will use the nihilo theme.</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a1a100;">@import url(yourdojodir/dijit/themes/nihilo/nihilo.css);</span><br />
<span style="color: #a1a100;">@import url(yourdojodir/dojox/form/resources/BusyButton.css);</span></div></td></tr></tbody></table></div>
<p>And add the theme CSS to your body tag:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nihilo&quot;</span>&gt;</span>...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/body.html"><span style="color: #000000; font-weight: bold;">body</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>JavaScript:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;script type=&quot;text/javascript&quot; src=&quot;yourdojodir/dojo/dojo.js&quot;&gt;&lt;/script&gt;<br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; dojo.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;dojox.form.BusyButton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></td></tr></tbody></table></div>
<h4>To create a button programatically, use following code:</h4>
<p>HTML:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;busyButton&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>JavaScript:</p>
<div class="codecolorer-container javascript twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dojo.<span style="color: #660066;">addOnLoad</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;">var</span> button <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> dojox.<span style="color: #660066;">form</span>.<span style="color: #660066;">BusyButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;id<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;submit&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;busyLabel<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sending mail...&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;label<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Send mail&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;timeout<span style="color: #339933;">:</span> <span style="color: #CC0000;">5000</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;busyButton&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></td></tr></tbody></table></div>
<h4>To create a button via normal markup:</h4>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/button.html"><span style="color: #000000; font-weight: bold;">button</span></a> dojotype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dojox.form.BusyButton&quot;</span> busylabel<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sending data...&quot;</span>&gt;</span>Send data<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/button.html"><span style="color: #000000; font-weight: bold;">button</span></a>&gt;</span></div></td></tr></tbody></table></div>
<h4>Following parameters can be passed besides the default dijit.form.Button ones, when creating the button</h4>
<p><strong>isBusy:</strong> This is really the internal state. When you pass it being true, the button will be busy initially<br />
<strong>busyLabel:</strong> This is the text you see when the button is busy<br />
<strong>timeout:</strong> a timeout, the button will be reset to original state after the timeout expires<br />
<strong>useIcon:</strong> set useIcon to false if you don&#8217;t want to see the loading icon</p>
<h4>Following methods besides the default dijit.form.Button ones, can be used or connected to</h4>
<p><strong>makeBusy():</strong> Changes the buttons state to busy and disables the button<br />
<strong>cancel():</strong> Resets the button to its normal state &#8211; enabled<br />
<strong>resetTimeout(/*Int*/ timeout):</strong> you can reset an existing timeout and set a new value. This is useful for chained responses<br />
<strong>setLabel(/*String*/ content, /*Int*/ timeout):</strong> lets you change the label of the button and connect an optional timeout to that label</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/08/02/dont-send-your-data-twice-a-little-widget/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

