Animate validation feedback using jQuery

Yesterday, I came across Jumpchart.com and while I was checking out their website one thing catched my eye: validation feedback was animated! In this tutorial I will explain how to create this nice little trick.

View demo

The trick is very simple: after user presses signup button, validation occurs and all fields that are invalid get shaken a little bit. They have very simple web form as example below shows. I won't explain the web form structure and styling here, but will rather focus on animation effect.

<ul>
    <li class="first">
        <h3>Your Name</h3>
        <p>
            <input type="text" value="First and Last name" id="name" name="name" /></p>
    </li>
    <li>
        <h3>Email</h3>
        <p>
            <input type="text" value="my@email.com" name="email"  /></p>
    </li>
    <li>
        <h3>Password</h3>
        <p>
            <input type="password" name="passwd" /></p>
    </li>
    <li>
        <h3>Password confirmation</h3>
        <p>
            <input type="password" name="passwd_conf"  /></p>
    </li>
    <li>
        <h3>User name</h3>
        <p>
            <input type="text" value="MyUserName" id="userName" name="user_name"  /></p>
    </li>
</ul>

This is how this demo works: when user presses signup button, jQuery will get all empty input fields. If there is at least one empty input field, an animation will be applied to field(s).

$("#signup").click(function() {
    var emptyfields = $("input[value=]");
    if (emptyfields.size() > 0) {
        emptyfields.each(function() {
            // animation goes here
        });
    }
}); 

Let's see how to create simple animation. We want to move each field 10px to the left, then 10px to the right, repeat this one more time and set them back to their original positions. Example on Jumpchart even randomizes animations, but I will keep it simple here.

$("#signup").click(function() {
    var emptyfields = $("input[value=]");
    if (emptyfields.size() > 0) {
        emptyfields.each(function() {
            $(this).stop()
                .animate({ left: "-10px" }, 100).animate({ left: "10px" }, 100)
                .animate({ left: "-10px" }, 100).animate({ left: "10px" }, 100)
                .animate({ left: "0px" }, 100)
                .addClass("required");
        });
    }
});

Signup on Jumpchart has one usability issue, though. After short animation user looses validation feedback. That is why we will add CSS class "required" to invalid fields that will change their borders to red. This is all you need.

Please keep in mind that this animation can't be substitution for static validation feedback. Each invalid input field should be clearly marked once validation fail. This only adds nice effect that helps catch the user's attention. It's the same as difference between saying "I am here" and "Hey, I'm here!". You can read more about validation in Web Form Validation: Best Practices and Tutorials article.

Do you have some nice and original example of validation feedback?

More articles in Blog archive or elsewhere
Advertisement

19 Comment(s)

webmasterdubai

webmasterdubai 16 Sep 2009 #

really nice you to use form validation with jquery, nice work

Karl Agius

Karl Agius 16 Sep 2009 #

Cool and straightforward... you really are back. ;) Was considering flashing some icons near invalid fields for some forms I was working on, but this beats it hands down! The way they're animated makes me want to add a tiny soundclip to the form - per form, not per error. Thanks for sharing!

Chris

Chris 16 Sep 2009 #

Approved and used.

Wolfgang

Wolfgang 16 Sep 2009 #

I am working on a feedback form with validation and was searching the web. Now I found this. The is a very fance idea. I love it! But I will combine this animation with additional feedback on error. Thanks for your work!

TNk

TNk 16 Sep 2009 #

Thats a nice approach for validation  Smile , the shake me me laugh lol

Ivan Minic

Ivan Minic 16 Sep 2009 #

Very neat! ;)

Al&#237;

Alí 16 Sep 2009 #

That's really cool. I'll use it as soon as posible!!!

Joe

Joe 17 Sep 2009 #

Great article, and thanks for the Jumpchart coverage!

Steffen J&#248;rgensen

Steffen Jørgensen 17 Sep 2009 #

Nice little and useful animation to catch the users' attention.

Sarfraz Ahmed

Sarfraz Ahmed 17 Sep 2009 #

that's great unique way to do it, learned some good jquery techniques as well , thanks Smile

zm

zm 18 Sep 2009 #

不错

Janko

Janko 18 Sep 2009 #

Thanks guys!

Abu Aufa's Weblog

Abu Aufa's Weblog 19 Sep 2009 #

Very Nice !

sobin

sobin 29 Sep 2009 #

How can I achieve this with asp.net text boxes and button ? Can I?

Gaurav

Gaurav 30 Sep 2009 #

Great tutorial Although this can be achieved by Adobe Spry 1.6.1 also and since it is very much integrated in DW, those designers who are not comfortable with coding can effectively use it. Just one glitch - the whole Spry effects library is very very heavy than jquery non mimimised itself.

I am a jquery fan though and love it. Thanks again for a great tutorial.

saurabh shah

saurabh shah 30 Sep 2009 #

cool ! going to use it now only for my site form ... thanks for sharing ...

dmantra

dmantra 12 Oct 2009 #

Great resources

Daniel

Daniel 18 Oct 2009 #

Jos jedan odlican plugin

Basin

Basin 20 Oct 2009 #

That's a great idea.  I have always felt that a great site is about a great user experience which includes a great visual experience.  It's the little details that count.  I implemented a Java plug-in for my checkout a while back that uses the common live field interactivity to limit page reloads and customers love it, not to mention it makes the site look more professional.

Comments are closed
via Ad Packs
9292