type: widget
release: 0.0
priority: medium
status: in planning
documentation: url || N/A
demo: url || N/A
1 - Description:
For users entering data into a form, we can provide a completely open text input or provide ways to offer or restrict users to a set of predefined values. From a text input, we can offer a range of UI tools that offer values to choose from or lock users into only choosing a predefined value.

Search auto-complete (F2) is a text input that displays a menu below the text input that offers suggested values that match the current string in the input and updates on every keyUp event. This does not constrain user input to set of values and needs to be validated since the user may choose to select a suggestion value by the clicking with the mouse or navigating via the arrow keyboard keys or continue typing in a value of their choosing. A variant of the auto-complete style that we might want to consider adding is used by Apple's iTunes application where the suggestions are offered within the text field instead of as a menu like this:
A combobox (F3)is also a text input with an search auto-complete feature except we offer an arrow icon button to the right of the input to allow the user to browse the full set of predefined values from the start with no typing required, similiar to a select box. Since this control is also a text input, it is unconstrained and may need to be validated.
A select or dropdown (F1) should behave just like a standard select box with all the single letter search and keyboard shortcuts expected in a native select element. The rationale for re-creating this element in jQuery would be for situations where the widget needs to be styled in a custom way or if there is a need to present richer formatting in the list of values (custom icons, background images, multiple lines of data, better typography, etc.). Since this control only allows users to select from the pre-defined list of values, the expected values are well-constrained and may not need additional validation. One thing to note on select boxes is that although the most common style places the menu directly below the feedback widget, on Apple OS X, they use a "pop-up menu" that opens the menu over the closed select, positioned so the selected value is centered on the select which is a very different positioning concept:


We have included a mockup of a custom dropdown that could be used to allow the user to select multiple values (F4). This is provided only for reference because this could probably be built by using the Position utility with a small embedded form but is worth discussing.
For more details on best practices, read Apple's UI guidelines for comboboxes and pop-up menus (select boxes)
Flexbox is a jQuery based combobox that could easily be tweaked to add progressive enhancement and few other features:
http://www.fairwaytech.com/flexbox/
jQuery Facebook Autocomplete is apparently built on top of Jorn's code which adds Facebook-style multiple-entry support to the plugin. Revamped multiple entry support should be a key consideration for the next release.
http://wharsojo.wordpress.com/2008/02/18/jquery-facebook-autocomplete/
2 - Visual Design:

3 - Functional Specifications/Requirements:
(Detailed descrition of how the script will be structured: defaults, options, architecture, extensibility, etc.)
Since Jorn's plugin from bassistance.de (http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/) has already been mostly ported to the development branch, I think a good starting point will be to update and assert that the current set of options, defaults and functionality matches the external plugin available.
Key:
Implemented
In Development
Not Implemented
Options:
Explanation for (most) options are identical to the list here: http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
- autoFill (boolean, default: false)
- cacheLength (number, default: 10)
- delay (number, default: 400 for remote, 10 for local)
- data (object | array, default: undefined)
- extraParams (object, default: null)
- formatItem (function, default: internal)
- formatMatch (function, default: internal)
- formatResult (function, default: internal)
- highlight (boolean, default: true) | (function, default: internal)
- matchSubset (boolean, default: true)
- matchCase (boolean, default: false)
- matchContains (boolean, default: false)
- max (number, default: 10)
- minChars (number, default: 1)
- multiple (boolean, default: true)
- multipleSeparator (string, default: ', ')
- mustMatch (boolean, default: false)
- scroll (boolean, default: true)
- scrollHeight (number, default: 180)
- selectFirst (boolean, default: true)
- url (string, default: undefined)
- width (number, default: calculated width of target)
Methods:
Callbacks:
Commands:
Constants:
Requirements:
- Handle erorrs when a url is used ( {url: ''} ) which is not on the same domain (cross domain request), or when a bad url is passed (uncaught exception: Access to restricted URI denied (NS_ERROR_DOM_BAD_URI).
- Handle errors/display message when the return code of a remote request is not 200.
4 - Markup & Style:
4.1 Initial markup examples
<input type="text" />
4.2 Recommended transformed HTML markup
http://jquery-ui.googlecode.com/svn/branches/dev/autocomplete/tests/static/autocomplete/default.html
4.3 Accessibility recommendation
Found in markup.
http://jquery-ui.googlecode.com/svn/branches/dev/autocomplete/tests/static/autocomplete/default.html
4.4 CSS & Theme
Found in markup (for now):
http://jquery-ui.googlecode.com/svn/branches/dev/autocomplete/tests/static/autocomplete/default.html
5 - Latest version of plugin:
http://jquery-ui.googlecode.com/svn/branches/dev/autocomplete/tests/visual/autocomplete/index.html
6 - Open issues being discussed
Andrew Powell said: "The company I work for has an immediate need for this , so I'm planning on getting the autocomplete widget in the /dev/ branch functional within the next two weeks or so. From SVN, it doesnt look as if that's being actively worked on. So hopefully if someone else is also working on it concurrently, they'll let us know :)"
Currently, JSON support in the Autocomplete as of 1.6rc2 is less than intuitive, as the developer has to transform the dataset into the format the plugin wants to consume (using the apparently undocumented "parse" callback). The plugin should certainly handle a dataType:"json", which would handle the JSON evaluation, and perhaps expose a a standardised JSON return format that spares the developer this gyration?
7 - Current Development Information
The plugin is presently being actively worked on.
Current Goals
- Initial goal is to assert that the demo available at bassistance.de (http://jquery.bassistance.de/autocomplete/demo) is functional with the widget framework port in the development branch.
- Update section 4 of this document to include all available options, defaults, methods, etc. for Specifications and continue on to collecting more Requirements.
Development Notes:
From '2 - Visual Design';
F2 is currently available.
F3 has a good start in this plugin.
Comments (17)
Jörn Zaefferer said
at 3:42 pm on Dec 17, 2008
The current autocomplete supports multiple complete (ala GMail "send to" field), but it really is rather broken: You can add values, and some callback is triggered for each value. But you're really lost once the user starts removing values. This is a problem when the display value maps to some id or index.
I think what the autcomplete needs for that to work properly is some more internal state: A stack with selected rows that is always in sync with the input field. When the user removes something from the field, the actual data row is removed from the stack as well. When values must match, which is usually the case when this behaviour is required, editing a value removes it from the stack as well, and therefore from the input on the next update.
That way it would be trivial to remove values from the input: Just delete one character, and the rest of the term is removed as well.
Richard D. Worth said
at 6:20 am on Mar 11, 2009
@Andrew Powell - great news. A great place to start would be Section 3. Functional Specifications/Requirements. In other words: we need to design it before we build it. For some examples of plugin pages with some specs already filled out, see:
http://wiki.jqueryui.com/Accordion
http://wiki.jqueryui.com/DatePickerCalendar
http://wiki.jqueryui.com/Dialog
http://wiki.jqueryui.com/Draggable
http://wiki.jqueryui.com/Droppable
http://wiki.jqueryui.com/Slider
http://wiki.jqueryui.com/Sortable
http://wiki.jqueryui.com/Tab
Andrew Powell said
at 12:59 pm on Mar 12, 2009
Food for thought:
In Windows development, when you choose to use a ComboBox, you can set the behavior of the control to act as a 'DropDownList'. See http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox_properties.aspx
The properties which are of interest to me are; AutoCompleteMode, AutoCompleteSource, and DropDownStyle (http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.dropdownstyle.aspx)
Perhaps it would be appropriate to rename this plugin 'ComboBox' and implement the autocomplete portion as a separate plugin/utility on which the ComboBox could then depend? Please share your thoughts.
Jörn Zaefferer said
at 5:01 pm on Mar 12, 2009
Looking at the visual designs, I agree with seperating ComboBox and autocomplete. A ComboBox would be a specialized Autocomplete that doesn't allow any new entries.
I disagree calling the Autocomplete a utility. Its just as important on its own. Considering the similarity between ComboBox and a html select, I'd even argue that the Autocomplete should have a higher priority.
It should be easy enough to split my old demo into individual demos based on the current demo format. To assert that this functionality keeps working, tests based on that would be the next step. Only then is refactoring and extending safe.
Jörn Zaefferer said
at 5:03 pm on Mar 12, 2009
About the URL exception: The plugin should be helpful in exposing common problems to the developer. It shouldn't make any descision on how to handle regular errors like connection errors. Usually those are handled by binding $().ajaxError. The plugin shouldn't swallow network problems.
Andrew Powell said
at 8:55 pm on Mar 12, 2009
@ Jörn
Please excuse the utility bit there. I'm still new the to project and didnt know what verbiage I should use there, so I included it to be safe.
I also have two instances of exceptions which were thrown, and your input on them would be much appreciated. Would you consider the following to be connection errors that we should let pass-through? (I'll post the actual Firefox exception message tomorrow if that's helpful)
- Cross Domain request exception
- Permission Denied exception (occurs in a very specific situation where credentials are required to access the url specified)
Todd Parker said
at 8:56 pm on Mar 22, 2009
I don't agree that a combobox never allows people to enter a new value, although sometimes it is (mis)used that way in some cases. In fact, that seems like the wrong UI widget for the job. If you cannot enter a new value and must choose from a list of values, a select (dropdown) is the better element to use because it provides a clearer affordance of this constraint. Selects do not look editable like an input to cue the user into the fact that they are choosing from a set list, not typing something new in.
A combobox should be used for cases where users can enter a new value (that's why it looks like an input) or pick from a preset list (button with down arrow to the right of the input). The URL bar in a browser is a classic example of a combobox: http://en.wikipedia.org/wiki/Combo_box -- you can type something new or pick from values.
Some comboboxes will pre-fill with the best match value as the user types, but I think it's used in many cases to force a user to only choose from a preset value which is sort of odd (see argument above). This is the MSFT 'DropDownList' option Andy mentioned and Apple does it too (See pref panel for timezone) but it is an exception, not the rule. I think they do this because selects only allow for searching on the first character (dunno why - no feedback on search characters?) but sometimes you need to let people enter multiple characters to winnow down to the right value and a select doesn't offer this capability.
If we created a custom select built on top of autocomplete, it could bold the matching letters for a visual affordance and allow for multi-letter searches - as you type letters, it selects the best match. That would be a better solution than this hacky combobox with select behavior thing.
Todd Parker said
at 8:57 pm on Mar 22, 2009
We've done some work on a PE based list builder which is basically the multiple recipient GMail example you mention. The best solution would start with either an input of textarea that can be populated with a set of comma/space/semi-colon (or whatever) delimited list of items that is enhanced into the whizzy auto-complete UI like Facebook or GMail. As a user adds or removes items, we update the original input/textarea and that serves as the "stack" to keep track of the items while also being a simple html element. Scott J. can post an example later this week if that would help.
Andrew Powell said
at 10:31 pm on Mar 22, 2009
>> The best solution would start with either an input of textarea that can be populated with a set of comma/space/semi-colon (or whatever) delimited list of items
That demo is in the dev branch too :)
branches/dev/autocomplete/demos/autocomplete/bassistance.de.html - 'Multiple Cities'
Jörn Zaefferer said
at 3:07 am on Mar 23, 2009
@Todd: Dylan, who built the original autocomplete plugin, created it for an application where the user could choose a value from a list of birds. The list is way too big to fit into a regular select, while new values weren't allowed. And there are a lot of scenarios like that, eg. City or Street names. Whatever our solution, it must supports this usecase.
Todd Parker said
at 5:39 am on Mar 23, 2009
@Andy - Thanks for the tip, I never would have found that demo (I get lost in all the branches). Here the link:
http://jquery-ui.googlecode.com/svn/branches/dev/autocomplete/demos/autocomplete/bassistance.de.html
...The multiple city with 'must match' is tricky from an interaction perspective. In this demo, if you start typing a city name (Boston) that isn't in the list when you get to "Bos", the script *deletes* the word when the "s" is Bos is typed because it doesn't match which feels really odd.
@Jorn From the demo, this is shaping up very nicely Jorn! Do you have an example of the autocomplete suggestion displaying inside the text input instead of a menu (see Apple screenshot at top). I agree that these 3 items should be separated out with autocomplete being finalized first because it's a dependency for select and combobox.
I didn't mean to suggest that the combobox shouldn't offer the 'dropdownlist' type option which would prevent new values from being entered, it should. I was just explaining that behavior should not be the *default* for the combobox since it's a bit of a misuse of the element and can be confusing to users that they are allowed to type but the system deletes their input like in the city example. Making the custom select allow for multiple letter searches would be a nice alternate that would accomplish the same thing but with a clearer affordance that new values aren't allowed.
I may have misunderstood you when you said above "A ComboBox would be a specialized Autocomplete that doesn't allow any new entries." -- I thought you were saying this is the default (or only behavior), but I think you meant that should be an option.
Jörn Zaefferer said
at 6:35 am on Mar 23, 2009
Yeah, thats more like it. I meant to describe the ComboBox as its own widget, where the implementation builds upon the autocomplete widget. With the ComboBox being more similar to a native select, but the ability to handle much larger datasets.
Displaying the dropdown-icon in the text input field should probably be an option of the autocomplete widget in any case - the ComboBox widget would then always enable it.
Multiple must-match autocomplete is indeed tricky. Just removing the user input is not a good interaction. Ideas for alternatives?
The Apple-style autocomplete isn't yet covered in the existing demos, and probably needs some modifications. Enable autoFill and make the autocomplete work without display the select box.
Andrew Powell said
at 7:05 am on Mar 23, 2009
@ Jorn
>> Displaying the dropdown-icon in the text input field should probably be an option of the autocomplete widget in any case - the ComboBox widget would then always enable it.
In what other situation would the autocomplete plugin add a similar button? Just playing devil's advocate here, but wouldnt adding the button to the autocomplete plugin be out of scope? It seems much more logical, and flexible, for a plugin like the comobox to implement the button, which triggers the autocomplete plugin/menu.
Jörn Zaefferer said
at 11:05 am on Mar 23, 2009
The button is a easy-to-find control to open the autocomplete list any time, producing the same result as a key input would otherwise. The currently plugin enables similar behaviour with a double click (focus field first, then click), but this behaviour is very hard to find, and I've seen a lot of requests for a button or some other way to open the select.
If something is actually displayed still depends on the content, eg. an empty input with minChars: 2 wouldn't display anything.
Andrew Powell said
at 11:17 am on Mar 23, 2009
Ah, that's a cool feature!
In that case, if we had a combobox plugin and it rendered a button, couldn't the combobox instruct the autocomplete to do it's thing when the button was clicked? I'm still in favor of plugins using the autocomplete plugin, rendering their own UI elements and instructing autocomplete on what to do when.
josuealcalde said
at 6:26 pm on Mar 26, 2009
I would like to see a tree select for one or many.
It would be a good replace for select with options like:
Option1
Option1 > Option11
Option2
Option3
Option3 > Option31
Option3 > Option32
Option3 > Option32 > Option 321
Or something like this:
Option1
--Option11
Option2
Option3
-- Option31
-- Option32
---- Option 321
<img src="/f/treeselect.png"/>
josuealcalde said
at 6:27 pm on Mar 26, 2009
Ups, the wiki does not support img. You can see a mockup here: https://jqueryui.pbwiki.com/f/treeselect.png
You don't have permission to comment on this page.