<?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>Design Shack &#187; validation</title>
	<atom:link href="http://designshack.net/tag/validation/feed" rel="self" type="application/rss+xml" />
	<link>http://designshack.net</link>
	<description>Inspiration, CSS Gallery &#38; Community News</description>
	<lastBuildDate>Thu, 09 Feb 2012 06:00:00 +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>Creating a Digg Style Sign Up Form</title>
		<link>http://designshack.net/articles/creating-a-digg-style-sign-up-form/</link>
		<comments>http://designshack.net/articles/creating-a-digg-style-sign-up-form/#comments</comments>
		<pubDate>Sun, 28 Sep 2008 11:19:12 +0000</pubDate>
		<dc:creator>Janko Jovanovic</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[digg]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[signup]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://localhost:8888/?p=137</guid>
		<description><![CDATA[Digg.com is one of the most popular social networking sites, allowing you to discover and share the content all over the web. In this tutorial we are going to simulate their signup form, with unique features such as their dynamic tooltips that give you a hint on each field that is to be filled. The [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://digg.com/">Digg.com</a> is one of the most popular social networking        sites, allowing you to discover and share the content all over the web. In this tutorial we are going to simulate their signup form, with unique features such as their dynamic tooltips that give you a hint on each field that is to be filled. The same approach will be adopted for displaying validation messages.</p>
<p>
Before we get started, you may like to <a href="http://www.designshack.net/tutorialexamples/diggform/" target="_blank">view a demo</a> of the end result.
</p>
<h2>
        How this form works?</h2>
<p>
        When an input field receives focus, a tooltip with a small blue icon is shown under it.         On the other hand, if validation fails, an error message is shown in the same place. Both cases are shown on the screenshot below.</p>
<p>
        <img height="138" alt="digg-field" src="http://www.designshack.net/postimages/digg-field.png" width="539" border="0">
    </p>
<h2>
        Let&#8217;s start</h2>
<p>
        We are not going to recreate the entire form, but rather a few fields just to see        how it works. Let&#8217;s take a closer look at the code sample. Each field row has        a label, an input field, an info message and a validation message. Below you can see the        HTML structure and CSS classes.</p>
<p>
        Note that, by default, both info and validation messages are hidden, which is set        in tooltipContainer CSS class.</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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span>“formContainer”&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Join Now! It’s quick and easy.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span>“rowContainer”&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span>“txtFirstname”&gt;</span>Choose a username<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span>“txtFirstname” <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span>“<span style="color: #000066;">text</span>” <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span>“tooltipContainer info”&gt;</span>Minimum 4 characters, maximum 15 characters. This is your handle on Digg so don’t make it too personal.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span>“tooltipContainer error”&gt;</span>Rats! Username must be between 4 and 15 characters.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
   // other rows here
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span> 
&nbsp;
body{
    font-family:Arial, Sans-Serif;
    font-size:83%;
}
.formContainer
{
    background-color: #F5EFC9;
    border:none;
    padding:30px;
}
.formContainer h3
{
    margin:0px;
    padding:0px 0px 10px 0px;
    font-size:135%;
}
.rowContainer
{
    width:100%;
    overflow:hidden;
    padding-bottom:5px;
    height:34px;
}
.rowContainer label
{
    width:140px;
    float:left;
    color: #758656;
    font-weight:bold;
}
.rowContainer input[type=“text”]
{
    width:200px;
}
.tooltipContainer
{
    height:16px;
    font-size:11px;
    color: #666666;
    display:none;
    float:none;
    background-repeat:no-repeat;
    background-position:left center;
    padding:0px 20px;
}
.info
{
    background-image:url(‘info.gif’);
}
.error
{
    background-image:url(‘error.gif’);
}</pre></td></tr></table></div>

<h2>
        Now let&#8217;s add some interactivity</h2>
<p>
        So far we have a static HTML structure and hidden messages waiting to be shown.  We have to write a few lines of code to make them appear/disappear. Of course, this can be accomplished by pure JavaScript, but let&#8217;s involve jQuery. The reason for this is quite simple &#8211; less coding.</p>
<p>
        Like I mentioned at the beginning of this tutorial, an info tooltip should be shown        each time an input field gets focus and hidden when it loses it. Turn this into jQuery        code and you get this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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>
    $<span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">formContainer</span> input<span style="color: #009900;">&#91;</span>type<span style="color: #339933;">=</span>text<span style="color: #009900;">&#93;</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</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>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">info</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span>“display”<span style="color: #339933;">,</span> “block”<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: #000066;">blur</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>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">info</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span>“display”<span style="color: #339933;">,</span> “none”<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>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
        Simple, isn&#8217;t it? Now, let&#8217;s see how to handle validation messages. We are        going to create fake validation just for the purpose of this tutorial. We&#8217;ll        use jQuery again.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> validateForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">formContainer</span> input<span style="color: #009900;">&#91;</span>type<span style="color: #339933;">=</span>text<span style="color: #009900;">&#93;</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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>
        <span style="color: #003366; font-weight: bold;">var</span> text <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span>“value”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>text <span style="color: #339933;">==</span> “”<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">error</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span>“display”<span style="color: #339933;">,</span> “block”<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>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>
        In essence, what the code above does is it shows a validation message for each field        that the user hasn&#8217;t entered text in. Please keep in mind that this is not real validation,        it just simulates what would happen if validation failed. You would have to implement        your own logic, eg. check for mandatory fields, email address format and so        on.</p>
<p>
        Ok, after pressing the sign-in button, validation messages will be shown. Signup        form on Digg.com hides these messages and replaces them with info tooltips when the user        starts to type. So we are missing a piece of code that will hide validation messages        that were previously shown.</p>
<p>
        Let&#8217;s do it the dirty way. We&#8217;ll extend our jQuery code that controls the appearance        of tooltips to hide corresponding validation messages each time an input field gets        focus.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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>
    $<span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">formContainer</span> input<span style="color: #009900;">&#91;</span>type<span style="color: #339933;">=</span>text<span style="color: #009900;">&#93;</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #000066;">focus</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>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">error</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span>“display”<span style="color: #339933;">,</span> “none”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">info</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span>“display”<span style="color: #339933;">,</span> “block”<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: #000066;">blur</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>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span>”.<span style="color: #660066;">info</span>”<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span>“display”<span style="color: #339933;">,</span> “none”<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>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>
        This way we have recreated the Digg.com signup form. You can check out <a href="http://www.designshack.net/tutorialexamples/diggform/" target="_blank">live demo</a>   or <a href="http://www.designshack.net/tutorialexamples/diggform/diggform.zip">download full source code</a>.</p>
<h2>
        Conclusion</h2>
<p>
        You saw how to recreate the Digg.com signup form with simple CSS and just        a few lines of jQuery code. However, there are a few pieces of advice I&#8217;d like to give you:</p>
<ul>
<li>Do not overwork the form &#8211; there is really no need for a tooltip that says &#8220;Enter            your first and last name in the field that says First and Last name&#8221;. Instead, you            can provide a message that shows a constraint, for example &#8220;Maximum 35 characters&#8221;.</li>
<li>Use tooltip/validation color other that text color &#8211; try hitting the &#8220;Continue&#8221; button            on Digg.com signup form before entering any text. The form becomes very hard to            read and it&#8217;s difficult to distinguish where one field ends and the next begins.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://designshack.net/articles/creating-a-digg-style-sign-up-form/feed/</wfw:commentRss>
		<slash:comments>72</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Object Caching 203/205 objects using disk: basic

Served from: designshack.net @ 2012-02-10 00:22:09 -->
