Hi,

I have a JS script that relies upon the 'autocompleteSelect' event.

If I use a core theme like bartik, everything goes fine: the event is fired once when I click on an item in the autocomplete list.

If I use the bootstrap theme, the event is fired twice.
It seems to be related to the fact that the misc/autocomplete.js script is overridden in the bootstrap theme.

Thank you in advance for your help.

Regards,

Martin

Comments

mduvergey created an issue. See original summary.

mduvergey’s picture

I'm able to get it working right by changing

for (var key in matches) {
    $('<li></li>')
      .html($('<a href="#"></a>').html(matches[key]).click(function (e) { e.preventDefault(); }))
      .mousedown(function () { ac.select(this); })
      .mouseover(function () { ac.highlight(this); })
      .mouseout(function () { ac.unhighlight(this); })
      .data('autocompleteValue', key)
      .appendTo(ul);
  }

to

for (var key in matches) {
    $('<li></li>')
      .html($('<a href="#"></a>').html(matches[key]).click(function (e) { e.preventDefault(); }))
      .mousedown(function () { ac.hidePopup(this); })
      .mouseover(function () { ac.highlight(this); })
      .mouseout(function () { ac.unhighlight(this); })
      .data('autocompleteValue', key)
      .appendTo(ul);
  }

but could someone validate this?

markhalliwell’s picture

Version: 7.x-3.5 » 7.x-3.x-dev
Status: Active » Postponed (maintainer needs more info)

This is relatively close to the same code in core: http://cgit.drupalcode.org/drupal/tree/misc/autocomplete.js?h=7.x#n221

I can only imagine that the difference here is that the link we're injecting (to match bootstrap's styling) is propagating the event upwards? I'm not entirely sure, but try the following:

for (var key in matches) {
  var $result = $('<a href="#"></a>')
    .html(matches[key])
    .click(function (e) {
      e.preventDefault();
      e.stopPropagation();
    });
  $('<li></li>')
    .append($result)
    .mousedown(function () { ac.select(this); })
    .mouseover(function () { ac.highlight(this); })
    .mouseout(function () { ac.unhighlight(this); })
    .data('autocompleteValue', key)
    .appendTo(ul);
}

  • markcarver committed 5f232b2 on 7.x-3.x authored by mduvergey
    Issue #2744401 by mduvergey, markcarver: autocompleteSelect event is...
markhalliwell’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.