r3401 committed - autocomplete: allow to pass value to search method, removing the need ...
Revision: 3401
Author: joern.zaefferer
Date: Mon Nov 2 11:55:35 2009
Log: autocomplete: allow to pass value to search method, removing the need
for emptying the value first; also smaller refactorings and cleanups
http://code.google.com/p/jquery-ui/source/detail?r=3401
Modified:
/branches/dev/tests/visual/autocomplete/combobox.html
/branches/dev/themes/base/ui.autocomplete.css
/branches/dev/ui/jquery.ui.autocomplete.js
=======================================
--- /branches/dev/tests/visual/autocomplete/combobox.html Fri Oct 23
09:16:15 2009
+++ /branches/dev/tests/visual/autocomplete/combobox.html Mon Nov 2
11:55:35 2009
@@ -69,10 +69,8 @@
input.autocomplete("close");
return;
}
- // need to temporarily remove value for search to display all options
- // find a better solution to avoid the flashing
- var val = input.val();
- input.val("").autocomplete("search").val(val);
+ // pass empty string as value to search for, displaying all results
+ input.autocomplete("search", "");
input.focus();
});
}
=======================================
--- /branches/dev/themes/base/ui.autocomplete.css Sat Sep 26 04:12:14 2009
+++ /branches/dev/themes/base/ui.autocomplete.css Mon Nov 2 11:55:35 2009
@@ -1,6 +1,6 @@
/* Autocomplete
----------------------------------*/
-.ui-autocomplete {}
+.ui-autocomplete-menu { position: absolute; }
.ui-autocomplete-loading { background: white
url('images/ui-anim.basic.16x16.gif') right center no-repeat; }
.ui-autocomplete-over { background-color: #0A246A; color: white; }
=======================================
--- /branches/dev/ui/jquery.ui.autocomplete.js Sun Nov 1 03:12:30 2009
+++ /branches/dev/ui/jquery.ui.autocomplete.js Mon Nov 2 11:55:35 2009
@@ -35,8 +35,6 @@
event.preventDefault();
break;
case $.ui.keyCode.ENTER:
- self.select();
- break;
case $.ui.keyCode.TAB:
self.select();
break;
@@ -53,7 +51,7 @@
// keypress is triggered before the input value is changed
clearTimeout(self.searching);
self.searching = setTimeout(function() {
- self.search(event);
+ self.search();
}, self.options.delay);
break;
}
@@ -92,15 +90,16 @@
}
},
- search: function() {
+ search: function(value) {
var self = this;
clearTimeout(self.closing);
- var value = this.element.val();
+ value = value !== undefined ? value : this.element.val();
if (value.length >= this.options.minLength) {
if (this._trigger("search") === false)
return;
self.element.addClass("ui-autocomplete-loading");
- self.term = value;
+ // always save the actual value, not the one passed as an argument
+ self.term = this.element.val();
function response(content) {
if (content.length) {
self._trigger("open");
@@ -155,13 +154,11 @@
var ul = $("<ul/>");
$.each(items, function(index, item) {
$("<li/>").data("item.autocomplete", item).append("<a>" + item.label
+ "</a>").appendTo(ul);
- });
- ul.css({
- position: "absolute"
- }).appendTo(document.body).menu({
+ })
+ ul.addClass("ui-autocomplete-menu").appendTo(document.body).menu({
focus: function(event, ui) {
self._trigger("focus", null, { item: ui.item.data("item.autocomplete")
});
- // use label or result?
+ // use result to match what will end up in the input
self.element.val(ui.item.data("item.autocomplete").result);
},
selected: function(event, ui) {