JamieAppleseed/selectToAutocomplete — pull request #24 by dontangg (2011-12-09 22:32:11+00:00)
Title: Restrict the typed value to an option in the hidden dropdown on blur

There are 3 commits in this pull request. I'll try to explain a little about each:

**Changed all tabs to 2 spaces**
This commit only fixes whitespace formatting. I noticed that 2 spaces were used in most cases. So, I switched all tabs to 2 spaces. Specifically, this makes it a lot nicer to look at on GitHub.com.

**Revert to previously selected value when the field loses focus and has an invalid value**
This is the main reason for these commits. If you accept this pull request, this table describes the behavior:

Action	Behavior

Type a partial match, then hit enter or tab	The full value matching your partial is inserted

Type a partial match and click somewhere other than the suggestions and text field	The previous valid value is inserted

Type a partial match, then hit escape, then hit enter or tab	The previous valid value is inserted

Type a completely invalid value and leave the field in any way	The previous valid value is inserted

When I say, "The previous valid value is inserted," I mean that the currently selected option from the hidden dropdown is inserted.

**Fixed bug where 'copy-attributes-to-text-field': false caused the text field to never be inserted into the dom**
While working on this, I noticed that the statements that actually add the text field to the DOM were inside the if statement that only executes when copy-attributes-to-text-field is true. So, I tested it and sure enough, the text field never appears on the page if that setting is set to false. Normally, I would put this in as a separate pull request, but since it affects the same lines of code, I thought this would be easier.

I am very willing to make tweaks or discuss this further if you have questions! Let me know.