Earlier this morning, in a fit of intense silliness - I tweeted an observation about reset buttons and forms:
Speaking of forms, why are we still adding Reset buttons? When was the last time you *intentionally* reset a form?
— Raymond Camden (@raymondcamden) November 3, 2015
Now, to be clear, I can't remember the last time I accidentally cleared a form, but it still surprises me when I see the element on a page. I honestly cannot remember ever wanting to reset my form and it just feels like a bit of wasted space.
But of course - as soon as I tweeted this I got some pretty interesting responses that made me re-examine my thoughts on the feature in general. Here they are in no particular order.
@raymondcamden @zeldman for CSS-only drop-down nav controlled by radio inputs, where a reset closes the active menu https://t.co/qAtmqPDazl
— Radoslav Sharapanov (@radogado) November 3, 2015
Ok, so that's an interesting demo there. To be honest, whenever I see CSS doing weird stuff with forms, I get a bit concerned. It seems cool to "twist" stuff that way but something about it just seems wrong to me. That being said, I can't CSS my way out of a paper bag so what do I know? In the end though, his demo/usage doesn't really match my initial statement about the "typical" use of the reset button.
@raymondcamden Only on a form used to filter search results (to reset it back to the default filter criteria).
— Dan Skaggs (@dskaggs) November 3, 2015
I replied back to Dan to clarify that he was talking about a form using Ajax and in that respect - I think it makes sense. As long as you change the value of the reset button to something like "Clear Search" and as long as you clear the results too, then I think this is actually a pretty darn valid use of the reset button.
And yes - you can listen for a reset event. I never knew it existed but it makes sense that it does. Here it is in jQuery:
$("form").on("reset", function(e) {
console.log("reset event");
console.dir(e);
});
And yes - if you return false from this event you can block a reset event. Why in the world would you do that? I have no idea. But you can.
As an aside - if you listen to the change event on a form field, even though reset technically changes the value (or may change the value), you will not get an event fired. I guess this makes sense, but if you are listening for change events and have a reset button, you'll want to listen for the reset event as well.
@raymondcamden I see them more used (and labelled) as "Cancel" which typically takes you back a page vs just clearing.
— Jordan Kasper (@jakerella) November 3, 2015
This examples makes sense too - and you would need to listen to the reset event to handle it. But as with my issue with the fancy CSS drop down menu thing, this feels like a small violation of the purpose of the button. Not that the W3C Police will come after you, but it seems wrong.
Don't forget that modern browsers support the formaction attribute. You could literally do this something like this:
<input type="submit" value="Cancel" formaction="index.html">
This only works on submit buttons though. Support is actually pretty good, and an article over on Wufoo documents this: The formaction attribute.
@raymondcamden Password-protected pages. Happens during testing and in daily use cases for our clients (work at a web dev. company)
— Sarah Jedrey (@sejedrey) November 3, 2015
So my take away from this is that Sarah's customers are asking for this on secured pages. I can't see why a customer would ask for this - but at the same time - I've got intimate knowledge of browsers that a casual user would not have. Seeing a way to remove form data with a single click could be reassuring. And in fact, a bit later Ben S said the same thing:
@raymondcamden @zeldman Funnily enough we just added them. Our users felt safer (in testing) knowing they could revert & restart their work.
— Ben S (@beseku) November 3, 2015
I guess I can see this helping users feel safe. As a reminder though, don't forget that the reset button doesn't "clear" forms, it literally resets it. So if your form is using hard coded values, perhaps on a "Edit Profile" page, the reset button isn't going to clear anything off screen. Rather it will just return the form back to its original values.
Any comments on this?
Archived Comments
I've hit so many reset buttons by accident when they are in the location of where you would expect the primary action button. I wouldn't be so angry if there was just an 'undo' reset that appears after hitting reset.
Why a reset function that you can use to cancel by returning 'false'?
Remember that window.confirm is a modal, synchronous, blocking dialog. You can use it to prompt the user if they made significant changes on whether or not they really want to reset them.
Granted, nobody uses the built-in window.confirm (or window.alert) anymore since they can't be styled, but remember this was state-of-the-art 1995-1997. HTML and javascript-DOM have a lot of cruft that nobody would ever recommend using, but as it was in the 1.0's of those days, they can't get rid of them...much as they should.
The other things to remember:
1) this was 1995, not 2015, and MOST people had never been on the web or entered web form information back then;
2) forms were used for editing existing, not just entering new, so a reset would keep you from damaging existing data. that was actually the more common use-case for it than a reset on a "new" object where the form was entirely empty. Again, a support for #1 - this was all VERY new to a lot of people.
in no way am i suggesting actually using reset anymore (there are better interaction mechanisms, though they require more code), just that the reasons for it existing at all made sense in that context.
Joe - thanks for sharing this. I've been building for the web since 1995 but it didn't occur to me to think in that context. Thanks!
Of course, there's always the tabbing. When the focus is on a reset button because a person - unfamiliar with how the Internet Webpages and their forms actually work - sometimes will remember the days of their typing class, back in high school, and hit the Enter key...reverting lots of time they have invested in making changes to their data online (in this form), will be quite upset. My wife was doing our taxes online, (fortunately, the IRS forms have only one textbox or dropdown per page) and she kept that right hand pinky finger on the "Carriage return" because of her typing classes. Decades ago, "Enter" on the keyboard meant a new line on the sheet of paper in the typewriter. I finally had to finish the tax forms last year. I tried telling her that you need to hit the tab key, honey...not the Enter key.