Created
November 4, 2013 18:03
-
-
Save jgdoncel/7306719 to your computer and use it in GitHub Desktop.
Jquery - Autocomplete comma values
From http://stackoverflow.com/questions/8716811/comma-separated-auto-complete-with-jquery-auto-complete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $("#<%= txtMultipleName.ClientID %>").autocomplete({ | |
| source: function (request, response) { | |
| $.getJSON("AutoComplete.ashx", { | |
| term: extractLast(request.term) | |
| }, response); | |
| }, | |
| search: function () { | |
| // custom minLength | |
| var term = extractLast(this.value); | |
| if (term.length < 1) { | |
| return false; | |
| } | |
| }, | |
| focus: function () { | |
| // prevent value inserted on focus | |
| return false; | |
| }, | |
| select: function (event, ui) { | |
| var terms = split(this.value); | |
| // remove the current input | |
| terms.pop(); | |
| // add the selected item | |
| terms.push(ui.item.value); | |
| // add placeholder to get the comma-and-space at the end | |
| terms.push(""); | |
| this.value = terms.join(", "); | |
| return false; | |
| } | |
| }); | |
| function split(val) { | |
| return val.split(/,\s*/); | |
| } | |
| function extractLast(term) { | |
| return split(term).pop(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment