Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comments
Comment #1
DimitriV CreditAttribution: DimitriV commentedPossible 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;
Comment #2
asheresque CreditAttribution: asheresque commentedThe 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.
Comment #3
2dareis2do CreditAttribution: 2dareis2do commentedsubscribe
Comment #4
janusman CreditAttribution: janusman commentedI am contemplating moving to the jQuery UI autocomplete widget, but only on the D7 branch.
Comment #5
kallehauge CreditAttribution: kallehauge commentedJust 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.
Comment #6
NitebreedAttached I added the patch I use (SVN, sorry). This seems to fix it for me.
Comment #7
NitebreedComment #8
Yorgg CreditAttribution: Yorgg commentedI 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.
Comment #9
NitebreedHmm for me it's working. I fixed another $.browser call in below patch, can you confirm it's working now?
Comment #10
Yorgg CreditAttribution: Yorgg commentedStill 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
Comment #11
Nitebreed@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)
Comment #12
Yorgg CreditAttribution: Yorgg commented@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.
Comment #13
NitebreedAh ok, I use the custom autocomplete widget so I don't experience that problem
Comment #14
trevorw CreditAttribution: trevorw commentedJust 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.
Comment #15
dgiamporcaro CreditAttribution: dgiamporcaro commentedHi, You can find in attachment a valid patch for the jQuery browser error for jQuery 1.9+
Comment #16
stred CreditAttribution: stred commentedI have rerolled the patch for git but anyway the solution should be to use the autocomplete.js from Drupal core...
Comment #17
stred CreditAttribution: stred commentedComment #18
stefan.r CreditAttribution: stefan.r commentedPatch looks great, re-roll attached.
Comment #19
janusman CreditAttribution: janusman at Acquia commentedTested this on Firefox/Chrome on Linux and IE/Firefox on Windows... looks like it works. Committed!