Monday, 15 June 2015

jQuery-ui autocomplete multiple values sort results alphabetically -



jQuery-ui autocomplete multiple values sort results alphabetically -

with reference question sorting autocomplete ui results based on match location, there solution provides single value jquery autocomplete possible similar solution multiple values jquery autocomplete (http://jqueryui.com/autocomplete/#multiple)?

the difference here need create sure , phone call extractlast demo linked doing. here's finish code should work multiple values (pay particular attending source option):

$("#tags") .on("keydown", function (event) { if (event.keycode === $.ui.keycode.tab && $(this).data("autocomplete").menu.active) { event.preventdefault(); } }) .autocomplete({ minlength: 0, source: function (request, response) { var term = $.ui.autocomplete.escaperegex(extractlast(request.term)) // create 2 regular expressions, 1 find suggestions starting user's input: , startswithmatcher = new regexp("^" + term, "i") , startswith = $.grep(source, function(value) { homecoming startswithmatcher.test(value.label || value.value || value); }) // ... , find suggestions contain user's input: , containsmatcher = new regexp(term, "i") , contains = $.grep(source, function (value) { homecoming $.inarray(value, startswith) < 0 && containsmatcher.test(value.label || value.value || value); }); // supply widget array containing suggestions start user's input, // followed contain user's input. response(startswith.concat(contains)); }, focus: function () { homecoming false; }, select: function (event, ui) { var terms = split(this.value); terms.pop(); terms.push(ui.item.value); terms.push(""); this.value = terms.join(", "); homecoming false; } });

example: http://jsfiddle.net/aa5nk/1/

jquery jquery-ui sorting jquery-ui-autocomplete

No comments:

Post a Comment