--- autocomplete.js 2008-01-04 11:53:21.000000000 +0000 +++ /Library/WebServer/Documents/drupal/misc/autocomplete.js 2009-12-30 10:22:19.000000000 +0000 /** * Attaches the autocomplete behavior to all required fields @@ -10,7 +10,7 @@ Drupal.behaviors.autocomplete = function if (!acdb[uri]) { acdb[uri] = new Drupal.ACDB(uri); } - var input = $('#' + this.id.substr(0, this.id.length - 13)) + var input = $('#' + this.id.substr(0, this.id.length - 13),context) .attr('autocomplete', 'OFF')[0]; $(input.form).submit(Drupal.autocompleteSubmit); new Drupal.jsAC(input, acdb[uri]); @@ -39,8 +39,13 @@ Drupal.jsAC = function (input, db) { $(this.input) .keydown(function (event) { return ac.onkeydown(this, event); }) .keyup(function (event) { ac.onkeyup(this, event); }) - .blur(function () { ac.hidePopup(); ac.db.cancel(); }); - + .blur(function () { + if (!ac.selected&&ac.db.cache[this.value]&&ac.db.cache[this.value][this.value]) { + ac.select({autocompleteKey:this.value,autocompleteValue:ac.db.cache[this.value][this.value]}); + } + ac.hidePopup(); + ac.db.cancel(); + }); }; /** @@ -103,7 +108,21 @@ Drupal.jsAC.prototype.onkeyup = function * Puts the currently highlighted suggestion into the autocomplete field */ Drupal.jsAC.prototype.select = function (node) { - this.input.value = node.autocompleteValue; + this.input.value = node.autocompleteKey; + $('.autocomplete-'+this.input.name).each(function () { + var $name; + if ($(this).hasClass("stripid")) { + var reg=/.*[^0-9]/; + $name = reg.exec(this.name); + } + else + $name = this.name; + if (this.type.indexOf("select")==0) { + $(this).val(node.autocompleteValue[$name]); + } + else + this.value = node.autocompleteValue[$name]; + }); }; /** @@ -155,7 +174,7 @@ Drupal.jsAC.prototype.unhighlight = func Drupal.jsAC.prototype.hidePopup = function (keycode) { // Select item if the right key or mousebutton was pressed if (this.selected && ((keycode && keycode != 46 && keycode != 8 && keycode != 27) || !keycode)) { - this.input.value = this.selected.autocompleteValue; + this.select(this.selected); } // Hide popup var popup = this.popup; @@ -205,14 +224,14 @@ Drupal.jsAC.prototype.found = function ( for (key in matches) { var li = document.createElement('li'); $(li) - .html('
'+ matches[key] +'
') + .html('
'+ key +'
') .mousedown(function () { ac.select(this); }) .mouseover(function () { ac.highlight(this); }) .mouseout(function () { ac.unhighlight(this); }); - li.autocompleteValue = key; + li.autocompleteKey = key; + li.autocompleteValue = matches[key]; $(ul).append(li); } - // Show popup with matches, if any if (this.popup) { if (ul.childNodes.length > 0) {