Making progress

When I was talking about Async, Ajax, and animation, I mentioned the little trick I’ve used of generating a progress element to indicate to the user that an Ajax request is underway.

I sometimes use the same technique even if Ajax isn’t involved. When a form is being submitted, I find it’s often good to provide explicit, immediate feedback that the submission is underway. Sure, the browser will do its own thing but a browser doesn’t differentiate between showing that a regular link has been clicked, and showing that all those important details you just entered into a form are on their way.

Here’s the JavaScript I use. It’s fairly simplistic, and I’m limiting it to POST requests only. At the moment that a form begins to submit, a progress element is inserted at the end of the form …which is usually right by the submit button that the user will have just pressed.

While I’m at it, I also set a variable to indicate that a POST submission is underway. So even if the user clicks on that submit button multiple times, only one request is set.

You’ll notice that I’m attaching an event to each form element, rather than using event delegation to listen for a click event on the parent document and then figuring out whether that click event was triggered by a submit button. Usually I’m a big fan of event delegation but in this case, it’s important that the event I’m listening to is the submit event. A form won’t fire that event unless the data is truly winging its way to the server. That means you can do all the client-side validation you want—making good use of the required attribute where appropriate—safe in the knowledge that the progess element won’t be generated until the form has passed its validation checks.

If you like this particular pattern, feel free to use the code. Better yet, improve upon it.

Have you published a response to this? :

Related posts

Unobtrusive feedback

An interface pattern for Ajax interactions that’s borrowed from video games.

Submitting a form with datalist

It can autocomplete, but how do you get it to autosubmit?

Am I cached or not?

Complementing my site’s service worker strategy with an extra interface element.

Async, Ajax, and animation

Hijax, Youjax, we all jax for Pjax.

Drag’n’drop revisited

An easy accessibility fix, courtesy of my past self.

Related links

How would you build Wordle with just HTML and CSS? | Scott Jehl, Web Designer/Developer

This is a great thought exercise in progressive enhancement …that Scott then turns into a real exercise!

Tagged with

Unpoly: Unobtrusive JavaScript framework

This looks like it could be an interesting library of interface patterns.

Tagged with

Easy Toggle State

I think about 90% of the JavaScript I’ve ever written was some DOM scripting to handle the situation of “when the user triggers an event on this element, do something to this other element.” Toggles, lightboxes, accordions, tabs, tooltips …they’re all basically following the same underlying pattern. So it makes sense to me to see this pattern abstracted into a little library.

Tagged with

Service Workers | Build Progressive

This is a really nice explanation of adding a service worker to your site to make it more resilient. This tutorial is part of an ongoing series that I’m really looking forward to reading more of.

Tagged with

Sticky headers

A three-part series by Remy looking at one interface pattern (a sticky header) and how his code evolved and changed:

  1. Sticky headers
  2. Smooth scroll & sticky navigation
  3. CSS sticky nav & smooth scroll

Tagged with

Previously on this day

12 years ago I wrote Told you so

In which I permit myself a moment to gloat about liquid layouts.

13 years ago I wrote Prix Fixe

Hyperlinks relating to CSS vendor prefixes.

15 years ago I wrote Linkrot

Let’s lynch the landlord.

22 years ago I wrote World of Ends

This is one the best articles about the fundamental nature of the internet that I’ve read.

23 years ago I wrote Text Editor Love

I love BBEdit, too. I’ve never composed a song in its honour, though:

23 years ago I wrote Flashy Accessibility

I attended two of Macromedia’s seminars over the last couple of days.