<?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>Cory O&#039;Daniel - These are just words &#187; stupidreferencestorandomthings</title>
	<atom:link href="http://coryodaniel.com/index.php/tag/stupidreferencestorandomthings/feed/" rel="self" type="application/rss+xml" />
	<link>http://coryodaniel.com</link>
	<description>Software development, thoughts, and randomness</description>
	<lastBuildDate>Thu, 17 Nov 2011 21:18:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>BabySteps &#8211; jQuery Step-by-Step Forms</title>
		<link>http://coryodaniel.com/index.php/2008/08/22/babysteps/</link>
		<comments>http://coryodaniel.com/index.php/2008/08/22/babysteps/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 22:57:31 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[babysteps]]></category>
		<category><![CDATA[stupidreferencestorandomthings]]></category>

		<guid isPermaLink="false">http://blog.vokle.com/?p=26</guid>
		<description><![CDATA[Just finished up my first jQuery plugin 'BabySteps' (yes, its Bill Murray reference).  BabySteps helps in breaking up long or complicated web forms into smaller steps without multiple page requests.  In the past when doing a multi-step form I'd generally have two or three pages that a user would have to go through, [...]]]></description>
			<content:encoded><![CDATA[<p>Just finished up my first jQuery plugin 'BabySteps' (yes, its Bill Murray reference).  BabySteps helps in breaking up long or complicated web forms into smaller steps without multiple page requests.  In the past when doing a multi-step form I'd generally have two or three pages that a user would have to go through, or I'd chalk up a bunch of javascript to shuffle divs around.</p>
<p>BabySteps takes the thinking out of breaking up forms.  Simply break your steps up into divs (or your container of choice) and hide them.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;style type=&quot;text/css&quot;&gt;
  .step{display: none;}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
  var step1 = $('#step1');
  var step2 = $('#step2');
  var step3 = $('#step3');
&nbsp;
  step1.bindStep(step2);
  step2.bindStep(step3);
&nbsp;
  $('#step1').show();
&lt;/script&gt;
}
&lt;/style&gt;
&lt;form method=&quot;post&quot; action=&quot;http://example.com/some/far/away/place&quot;&gt;
  &lt;div id=&quot;step1&quot; class=&quot;step&quot;&gt;
    &lt;!-- STEP 1 stuff here --&gt;
  &lt;/div&gt;
  &lt;div id=&quot;step2&quot; class=&quot;step&quot;&gt;
    &lt;!-- STEP 2 stuff here. --&gt;
  &lt;/div&gt;
  &lt;div id=&quot;step3&quot; class=&quot;step&quot;&gt;
    &lt;!-- STEP 3 stuff here. --&gt;
    &lt;input type=&quot;submit&quot; id=&quot;frm_submit_btn&quot; /&gt;
  &lt;/div&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>And thats it.  When your page loads 'step 1' will show.  At the bottom a 'next' button will be appended.  Click the next button and 'step 2' appears with a 'next' and 'previous' button.</p>
<p>Ok maybe you are thinking, well that's great, but I'd really like to customize what my form transitions look like.</p>
<p>Ok, cool.  I can deal with that.  BabySteps has a number of configurable parameters (globally or individually configurable):</p>
<ul>
<li>nextBtn - path to your next button</li>
<li>prevBtn - path to your previous button</li>
<li>bindPrev - Do you want a previous button on the next page?</li>
<li>transition - how you want to transition from one step to the next</li>
<li>layoutButton - how you want to lay your button out over/in your step</li>
<li>generateMarkup - the markup you want to use to create your button</li>
<li>nextValidator - callback that runs a validator on next buttons 'onclick' should return boolean</li>
</ul>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//These are each globally or individually configurable... :)</span>
$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">bindStep</span>.<span style="color: #003366; font-weight: bold;">default</span>.<span style="color: #660066;">nextBtn</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/images/path/to/my/next.gif'</span><span style="color: #339933;">;</span>
$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">bindStep</span>.<span style="color: #003366; font-weight: bold;">default</span>.<span style="color: #660066;">prevBtn</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'/images/path/to/my/prev.gif'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> step1 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#step1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> step2 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#step2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Dont like the default hide/show?</span>
step1.<span style="color: #660066;">bindStep</span><span style="color: #009900;">&#40;</span>step2<span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
  transition<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>currStep<span style="color: #339933;">,</span>nextStep<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    currStep.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    nextStep.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Dont like the &lt;img&gt; wrapped in &lt;div&gt;?</span>
$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">bindStep</span>.<span style="color: #660066;">defaults</span>.<span style="color: #660066;">generateMarkup</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>id1<span style="color: #339933;">,</span>id2<span style="color: #339933;">,</span>img<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">//id1 is the id the events are bound to (default DIV)</span>
  <span style="color: #006600; font-style: italic;">//id2 is an extra id for the inner element (default img), if you dont have an inner, just ignore it</span>
  <span style="color: #000066; font-weight: bold;">return</span><span style="color: #009900;">&#40;</span>
  <span style="color: #009900;">&#91;</span>
    <span style="color: #3366CC;">'&lt;img '</span><span style="color: #339933;">,</span>
      <span style="color: #3366CC;">'src=&quot;'</span> <span style="color: #339933;">+</span> img <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; '</span><span style="color: #339933;">,</span>
      <span style="color: #3366CC;">'id=&quot;'</span> <span style="color: #339933;">+</span> id1 <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; '</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">'/&gt;'</span>
  <span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Woot, pretty much everything is a callback, so you can modify the way the buttons are laid out, how their markup is generated and even how they transition.  Of course there are also defaults, so now, it's up to you whether or not you want to just do the bare minimum. Well, like Brian, for example, has 37 cool transitions.</p>
<p>Here is a SIMPLE example of using the nextValidator.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<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>
  <span style="color: #006600; font-style: italic;">//get references to my 4 steps</span>
  <span style="color: #003366; font-weight: bold;">var</span> s1 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#step1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> s2 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#step2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> s3 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#step3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> s4 <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#step4'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  s1.<span style="color: #660066;">bindStep</span><span style="color: #009900;">&#40;</span>s2<span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
    nextValidator<span style="color: #339933;">:</span> step1_validator
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  s2.<span style="color: #660066;">bindStep</span><span style="color: #009900;">&#40;</span>s3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  s3.<span style="color: #660066;">bindStep</span><span style="color: #009900;">&#40;</span>s4<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/* The nextValidator doesn't care what goes on
 * inside the validation method/closure as long
 * as it returns true|false.  If it gets true, the
 * next button works, if it gets false, it doesn't
 * All error reporting/validation is up to you or
 * your validation plugin.
 *
 * Simple example of validation that a username,
 * password, and password confirmation are entered
 * before moving on to the rest of the sign up form.
 *
**/</span>
<span style="color: #003366; font-weight: bold;">function</span> step1_validator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#username'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#password'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#password_confirm'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You may be saying, 'where can I get this swell tool?'  Well from jQuery's <a href="http://plugins.jquery.com/project/babysteps">plugins page</a> of course.</p>
<p>UPDATE:<br />
Here's a <a href="http://static.coryodaniel.com/stuff/examples/babysteps/index.html">demo!</a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=BabySteps+%E2%80%93+jQuery+Step-by-Step+Forms+http://bit.ly/cjzxJo" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2008/08/22/babysteps/&amp;title=BabySteps+%E2%80%93+jQuery+Step-by-Step+Forms" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2008/08/22/babysteps/&amp;t=BabySteps+%E2%80%93+jQuery+Step-by-Step+Forms" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2008/08/22/babysteps/&amp;title=BabySteps+%E2%80%93+jQuery+Step-by-Step+Forms" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2008/08/22/babysteps/&amp;title=BabySteps+%E2%80%93+jQuery+Step-by-Step+Forms" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2008/08/22/babysteps/feed/</wfw:commentRss>
		<slash:comments>81</slash:comments>
		</item>
	</channel>
</rss>

