--- autocomplete.js 2012-02-01 22:03:14.000000000 +0000 +++ ../../d7-work/misc/autocomplete.js 2012-04-04 23:50:51.000000000 +0000 @@ -11,7 +11,7 @@ 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') .attr('aria-autocomplete', 'list'); $($input[0].form).submit(Drupal.autocompleteSubmit); @@ -41,14 +41,20 @@ Drupal.jsAC = function ($input, db) { var ac = this; this.input = $input[0]; - this.ariaLive = $('#' + this.input.id + '-autocomplete-aria-live'); + this.ariaLive = $('#' + $input.attr('id') + '-autocomplete-aria-live'); this.db = db; $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]) { + $input.data('autocompleteValue',ac.db.cache[this.value][this.value]); + ac.select($input); + } + ac.hidePopup(); + ac.db.cancel(); + } ); }; /** @@ -111,7 +117,28 @@ * Puts the currently highlighted suggestion into the autocomplete field. */ Drupal.jsAC.prototype.select = function (node) { - this.input.value = $(node).data('autocompleteValue'); + var autocompleteValue = $(node).data('autocompleteValue'); + this.input.value = autocompleteValue['key']; + $('.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(autocompleteValue[$name]); + } + else if (this.type.indexOf("checkbox")==0) { + if ((autocompleteValue[$name]==1)||(autocompleteValue[$name]=='true')||(autocompleteValue[$name]==true)) + $(this).attr('checked', true); + else + $(this).attr('checked', false); + } + else + this.value = autocompleteValue[$name]; + }); }; /** @@ -165,7 +192,8 @@ 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).data('autocompleteValue'); + this.select(this.selected); + //this.input.value = $().data('autocompleteValue')['key']; } // Hide popup. var popup = this.popup; @@ -216,12 +244,15 @@ var ul = $(''); var ac = this; for (key in matches) { + var match = new Array(); + match.key = key; + match.title = (matches[key].title?matches[key].title:matches[key]); $('
  • ') - .html($('
    ').html(matches[key])) + .html($('
    ').html(match.title)) .mousedown(function () { ac.select(this); }) .mouseover(function () { ac.highlight(this); }) .mouseout(function () { ac.unhighlight(this); }) - .data('autocompleteValue', key) + .data('autocompleteValue', match) .appendTo(ul); }