Do not enable autocomplete deluxe for all autocomplete fields on a page

Created on 6 January 2016, almost 9 years ago
Updated 15 September 2024, 3 months ago

Hi,

I have the problem that fields, where autocomplete deluxe is enabled interfere with other autocomplete fields, which are on the same page. For example on a page where I have several autocomplete deluxe fields, I have a search box where "Search Autocomplete" ( https://www.drupal.org/project/search_autocomplete ) is enabled. All fields, where the autocomplete deluxe widget is enabled, are working, but the search box doesn't show me results. After googling a bit arround I have found that the Monkey patch for the _renderItem affects all autocomplete fields on a page and therefore destroys autocompletion on my search box. For now I have partially solved this by creating the _renderItem function for all autocompletes with class "autocomplete-deluxe-form" (see below, autocomplete_deluxe.js). This works in most cases, but sometimes the autocomplete output shows the pure html (i.e. <div>result</div>), but still works.

Not sure how to solve this properly so please help...

     // Monkey patch the _renderItem function jquery so we can highlight the
     // text, that we already entered.
-    $.ui.autocomplete.prototype._renderItem = function( ul, item) {
-      var t = item.label;
-      if (this.term != "") {
-        var escapedValue = Drupal.autocomplete_deluxe.escapeRegex( this.term );
-        var re = new RegExp('()*""' + escapedValue + '""|' + escapedValue + '()*', 'gi');
-        var t = item.label.replace(re,"<span class='autocomplete-deluxe-highlight-char'>$&</span>");
-      }
-
-      return $( "<li></li>" )
-        .data(autocompleteDataKey, item)
-        .append( "<a>" + t + "</a>" )
-        .appendTo( ul );
-    };
+    $('.autocomplete-deluxe-form').autocomplete({
+      create: function() {
+        $(this).data('ui-autocomplete')._renderItem = function( ul, item) {
+          var t = item.label;
+          if (this.term != "") {
+            var escapedValue = Drupal.autocomplete_deluxe.escapeRegex( this.term );
+            var re = new RegExp('()*""' + escapedValue + '""|' + escapedValue + '()*', 'gi');
+            var t = item.label.replace(re,"<span class='autocomplete-deluxe-highlight-char'>$&</span>");
+          }
+
+          return $( "<li></li>" )
+            .data(autocompleteDataKey, item)
+            .append( "<a>" + t + "</a>" )
+            .appendTo( ul );
+        };
+        }
+    });
   };

   Drupal.autocomplete_deluxe.Widget.prototype.generateValues = function(data) {
🐛 Bug report
Status

Closed: outdated

Version

2.1

Component

Single values

Created by

🇩🇪Germany h1nds1ght

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024