|
In 2009 I was working as a frontend engineer for an e-commerce agency and received this bug: The bug said: Pressing enter when the ‘Town’ input is focused performs a postcode search.
Pressing ENTER should only perform a postcode search when the postcode input is focused.
This problem is much harder than it sounds so let me break it down: Forms have two types of submission:
Explicit submission is when you click the submit button. Implicit submission is when you press ENTER when an input is focused. When a form has one submit button, there’s no difference between explicit and implicit submission: You either click the button to submit the form. Or you press ENTER to submit the form. Both result in the ‘Continue’ action being performed. But what happens when you have two buttons: I didn’t know at the time so I ran some tests and found out that: Browsers submit the form as if you clicked the first button. So no matter what input has focus, pressing ENTER will submit the form as if you clicked ‘Find address’. Root cause found! To solve this, you need to add another ‘Continue’ button to the top of the form: But showing a duplicate button at the top of the form isn’t ideal, isn’t conventional and didn’t match the original design. Here’s how I solved it (get ready to be impressed): Step #1: Visually hiding the ‘Continue’ buttonI used CSS to hide the button off screen:
This way the button is hidden from users but still picked up by the browser when the form is submitted. Step #2: Making the ‘Continue’ button non-focusableEven though the button was off-screen, when you tab into the ‘First name’ input the interface would appear broken. This is because the off-screen button received focus. To fix this I added That worked perfectly except for when the postcode input received focused: This is because it performs the ‘Continue’ action when it should perform the ‘Find address’ action. Here’s my really clever solution: Step 3: Performing the postcode search when the postcode input is focusedTo do this I used JavaScript to add another visually hidden ‘Find address’ button to the top - but only when the postcode input received focus: And then when the postcode input loses focus, the JavaScript removes the button: Impressive right? Well not really:
You gotta remember that: The task was not to overcome the way browsers handle implicit submission when there are multiple buttons. The task was to help users enter their details. And multiple submit buttons makes that harder. Because users then have to use the right button, in the right order, at the right time. Instead redesign the interaction so that you don’t need multiple submit buttons: It’s not clever, but it is. My course, Form Design Mastery is full to the brim of ‘not clever, but clever’ solutions. Here’s a link in case you’re interested: https://formdesignmastery.com Cheers, |
Join 10,000+ designers, content designers and engineers who get my free weekly newsletter with evidence-based design tips (in 3 minutes or less). Mostly forms UX, but not always.
I’ve just listened to Rick Beato break down “What’s My Age Again?” — Blink-182’s second biggest hit. Funnily enough, he kicked off his "What Makes This Song Great?" series with their biggest hit — "All The Small Things". One person commented: I can’t believe you started the series with All The Small Things when it’s all the small things that makes the song so great. In the chorus of “What’s My age Again?”, Rick points out how most bass guitarists would play continuously, but Blink-182 left a...
I’ve just listened to Rick Beato break down “What’s My Age Again?” — Blink-182’s second biggest hit. Funnily enough, he kicked off his "What Makes This Song Great?" series with their biggest hit — "All The Small Things". One person commented: I can’t believe you started the series with All The Small Things when it’s all the small things that makes the song so great. In the chorus of “What’s My age Again?”, Rick points out how most bass guitarists would play continuously, but Blink-182 left a...
I didn’t start out as a designer. I started out as a frontend developer. I cared about the craft and spent a lot of time trying to master HTML, CSS, JavaScript and accessibility. Over time, I learned how these technologies affected UX, so as a dev, I started to suggest design changes to improve usability and accessibility. But most of the designers I worked with ignored my suggestions. Years later I transitioned to design. I tried to hide my engineering past because I was worried other...