Turning standard drop-downs into advanced auto-complete fields
During our large-scale checkout ux study we found several usability issues when using a drop-down for your country selector: a lack of overview, unclear sorting, scrolling issues, inconsistent UIs, a lack of context on mobile devices, and finally, they break the user’s tab-flow.
So we took it upon ourselves to redesign the country selector.
Using principles of progressive enhancement we turn a standard drop-down into an advanced auto-complete field. This means the drop-down remains accessible, while providing a much better experience in modern browsers - handling typos, multiple spelling sequences, synonyms and prioritization.
You can read the more about the design process and usability aspects in our article on Smashing Magazine: Redesigning the Country Selector.
To be notified about future improvements, follow the project on GitHub.
You can download the plugin here (.zip), or simply grab it from the GitHub repository.
It's based on the ISO 3166, and no, you don't have to use it. In fact, the idea is that you add this plugin to your existing country list – not replace your country list itself. We simply added the ISO 3166 country list as an example.
No. The code simply replace ordinary drop-downs (or 'select' tags), and is therefore not limited to country selectors. Any drop-down on your site can be used. For example, we've used it as an auto-complete to look up DSLR camera models at LensHawk.com.
Yes and no. In IE6 and IE7 nothing happens and the normal drop-down is displayed. In other words, it doesn't break your site in IE6 and IE7, but the drop-down won't be turned into an advanced auto-complete field either. IE8+ works along with Firefox, Chrome, Opera and Safari.
No. Everything happens front-end and the auto-complete options are simply taken from the original drop-down so there's no requests to your server (plus searching happens instantly).
No. In fact, the auto-complete plugin is completely separate from this plugin. We include the jQuery UI Autocomplete by default but you can use any auto-complete plugin (see next question).
Yes. We've deliberately not built the auto-complete part. Instead, there's adapters that allow you to use the plugin with any auto-complete plugin. Currently, there's only a jQuery UI Autocomplete adapter but more may be added if the interest is there.
The plugin is released under the MIT License:
Copyright (C) 2011 by Jamie Holst, Baymard Institute (baymard.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Note: the included jQuery plugins are (obviously) under their noted licenses.
Be sure to include the dependencies and then the selectToAutocomplete plugin.
Now you simply need to call the '.selectToAutocomplete' function on a jQuery selection once the DOM is ready. For example, to turn all select
elements with a class of turn-to-ac
, you'd simply need to call:
jQuery(function(){
jQuery('select.turn-to-ac').selectToAutocomplete();
});
If you just want to use the default configuration and the jQuery UI Autocomplete plugin then this is it. Otherwise, check below too see how you can customize the auto-complete and write an adaptor for your own auto-complete plugin.
There's a whole host of options you can pass to the plugin (as first and only parameter), some of which give you access to the internals of the plugin. Here I'll cover a few of the most common customizations:
For example, if you don't want the attributes of the 'select' tag to be copied over to the new auto-complete text field, then you'd do something like this:
$('.turn-to-ac').selectToAutocomplete({
'copy-attributes-to-text-field': false
});
The selectToAutocomplete plugin allows you to use your own auto-complete plugin. By default we include the jQuery UI Autocomplete and there's a pre-written adapter for it, but if you want to (re)use your own auto-complete plugin then it's actually quite easy to write an adapter.
Just pass in an 'autocomplete-plugin' function as part of the options hash. This is your adapter function.
The function should accept one parameter which is a hash containing 4 keys:
value
attribute.option
tags.