The autocomplete js uses the .browser jQuery function, which has been deprecated since v1.3 and completely removed in v1.9 - http://api.jquery.com/jQuery.browser/

Can the autocomplete js be updated to comply with the latest version of jQuery?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DimitriV’s picture

Possible patch:

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- HEAD
+++ Modified In Working Tree
@@ -78,8 +78,14 @@

var blockSubmit;

+ jQuery.browser = {};
+ jQuery.browser.mozilla = /mozilla/.test(navigator.userAgent.toLowerCase()) && !/webkit/.test(navigator.userAgent.toLowerCase());
+ jQuery.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase());
+ jQuery.browser.opera = /opera/.test(navigator.userAgent.toLowerCase());
+ jQuery.browser.msie = /msie/.test(navigator.userAgent.toLowerCase());
+
// prevent form submit in opera when selecting with return key
- $.browser.opera && $(input.form).bind("submit.autocomplete", function() {
+ jQuery.browser.opera && $(input.form).bind("submit.autocomplete", function() {
if (blockSubmit) {
blockSubmit = false;
return false;
@@ -87,7 +93,7 @@
});

// only opera doesn't trigger keydown multiple times while pressed, others don't work with keypress at all
- $input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
+ $input.bind((jQuery.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
// a keypress means the input has focus
// avoids issue where input had focus before the autocomplete was applied
hasFocus = 1;
@@ -732,7 +738,7 @@
overflow: 'auto'
});

- if($.browser.msie && typeof document.body.style.maxHeight === "undefined") {
+ if(jQuery.browser.msie && typeof document.body.style.maxHeight === "undefined") {
var listHeight = 0;
listItems.each(function() {
listHeight += this.offsetHeight;

asheresque’s picture

The above patch by frontview does not address the problem of the deprecated "browser" function. It addresses a different and more general jQuery/Drupal compatibility problem. But the more serious problem remains unsolved: has anyone developed a patch that will remove the use of the deprecated function? If so, it would be great if you could share it.

2dareis2do’s picture

subscribe

janusman’s picture

I am contemplating moving to the jQuery UI autocomplete widget, but only on the D7 branch.

kallehauge’s picture

Just a small note from me since I'm in the same dilemma right now. According to his (Jörn Zaefferer) blog, the jquery.autocomplete.js library is deprecated. So moving to jQuery UI autocomplete (as @Janusman said in #4) instead of using something like https://github.com/devbridge/jQuery-Autocomplete (new maintainer but the same library) would only make sense. Imo, jQuery UI is the way to go (only based on being provided by the jQuery UI library, so it will have a higher chance of longer support and the jQuery UI is already in Drupal anyway).
I'll try and see if I have time to make a patch in the very near future but the sad truth is that you can simply downgrade your jQuery version and it would still work. So if you're currently stuck, this might be a temporary solution for you.

Nitebreed’s picture

Attached I added the patch I use (SVN, sorry). This seems to fix it for me.

Nitebreed’s picture

Status: Needs work » Needs review
Yorgg’s picture

I tried but it's not capturing the text suggested by the autocomplete to provide the query for solr.
Updating jquery from 1.7 to 1.9 also breaks the focus module.

Nitebreed’s picture

Hmm for me it's working. I fixed another $.browser call in below patch, can you confirm it's working now?

Yorgg’s picture

Still doesn't pickup the suggestion string in Safari but is not passing it to apachesolr search unless I force the widget submition with the Enter key.
I am also using jQuery Multi jQuery library 2.1.0 and it works well with jQuery 1.7 and focus module. Would it be a too much making it work with any of these? Thanks

Nitebreed’s picture

@j_nunes, Which autocomplete widget do you use? The custom one or the default one? I know the default one needs an enter to submit whereas the custom doesn't (see admin/config/search/apachesolr/settings)

Yorgg’s picture

@Nitebreed: I am using Drupal's autocomplete widget.
Of course I need to select first and the hit submission, but if I type "yellow" and there is a suggestion for "yellow bird", only yellow would be sent to solr for search.
The custom autocomplete widget works well.

Nitebreed’s picture

Ah ok, I use the custom autocomplete widget so I don't experience that problem

trevorw’s picture

Just used the patch posted in #9 and confirmed it fixed the jQuery browser error for jQuery 1.9+. Posting here to provide some feedback, would hope after 1.5 years this would get included in the base module code. Thanks for the patch and time to resolve.

dgiamporcaro’s picture

Hi, You can find in attachment a valid patch for the jQuery browser error for jQuery 1.9+

stred’s picture

I have rerolled the patch for git but anyway the solution should be to use the autocomplete.js from Drupal core...

stred’s picture

stefan.r’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community
FileSize
1.61 KB

Patch looks great, re-roll attached.

janusman’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Status: Reviewed & tested by the community » Fixed

Tested this on Firefox/Chrome on Linux and IE/Firefox on Windows... looks like it works. Committed!

  • stefan.r authored 3afc13f on 7.x-1.x
    Issue #2138429 by Nitebreed, stred, dgiamporcaro, stefan.r: Autocomplete...

Status: Fixed » Closed (fixed)

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