Autocomplete in core is limited when it comes to show long list as result, there are various ways to get the long list, I am not getting in to that..
The issue is that if we apply overflow: auto; to the following div, it gives us a vertical scroll, now this scroll works fine in FF, but in IE & Chrome when we try to scroll the list as soon as we click on the scroll the autocomplete result popup disappears.
I have a patch to fix this.. but first we need to reproduce this behavior, just apply any where in CSS
#autocomplete ul{
overflow: auto;
max-height: 100px;
}
#autocomplete li{
white-space: pre-line;
}after refreshing a page try to run the string search in autocomplete field in any browser and you will find that scrolls are not working in Chrome and IE.
to fix this behavior run the patch
diff --git a/misc/autocomplete.js b/misc/autocomplete.js
index 8f7ac60..b52d6af 100644
--- a/misc/autocomplete.js
+++ b/misc/autocomplete.js
@@ -22,6 +22,16 @@ Drupal.behaviors.autocomplete = {
);
new Drupal.jsAC($input, acdb[uri]);
});
+
+ // fix autocomplete scrollbar issue
+ $('*').click(
+ function(event) {
+ if (!$(this).children('div:first').is('#autocomplete') && Drupal.settings.autocompleteCurrent) {
+ Drupal.settings.autocompleteCurrent.hidePopup();
+ Drupal.settings.autocompleteCurrent.db.cancel();
+ }
+ }
+ );
}
};
@@ -47,7 +57,7 @@ Drupal.jsAC = function ($input, 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 () { Drupal.settings.autocompleteCurrent = ac; });
};| Comment | File | Size | Author |
|---|---|---|---|
| #26 | autocomplete-overflow-1809580-26.patch | 1.12 KB | ruscoe |
| #23 | autocomplete-overflow-1809580-23.patch | 1.12 KB | ruscoe |
| #22 | autocomplete-overflow-1809580-22.patch | 999 bytes | crmn |
| #21 | autocomplete-overflow-1809580-21.patch | 1.09 KB | mrdalesmith |
| #18 | autocomplete-overflow-1809580-18.patch | 1.07 KB | mrdalesmith |
Comments
Comment #1
xjmThanks Qandeel for the report.
This is not a major bug. I'm not actually sure it's a bug at all, since if I understand correctly, you have to add custom CSS that is not in core in order to trigger the bug? Demoting to normal, at least.
Let's have someone try reproducing this bug in D8 using the steps in the summary above, and confirm whether the autocomplete shows any problems normally. Please document exactly the steps you take to test it, starting from "Install Drupal core with the standard profile."
Comment #2
seutje commentednot a big fan of the shorthand methods (click, load, ...), but autocomplete in D7 is full of em, would still prefer
.bind('click'(or.on('click'in 8) thoughalso, it's probably better to bind to document (or body) and use
event.targetinstead ofthisComment #3
iflista commentedDrupal 8 Testing
I have tested Chrome, Firefox and Safari behavior for drupal 8 and it's the same in every browser. I suppose that 4 fields for auto-complete is default drupal's behavior and it's also not a bug.
My observation:
As you can see there is a problem but not the same as in issue description. Logically the last number showed should be 1-st or second but not the last.
Drupal 7 Testing
Testing was made with different taxonomies but still the same behavior, the most obvious variants were last or in the middle of list.
The only difference between 2 versions is that d8 shows 4 variants and less, and d7 - 5 variants and less.
I found issue that tries to fix described behavior in this comment #1120144: Term Reference Autocomplete widget - add option to match only start of term and expose settings (size, match)
And also to indicate that more results were found than displayed #100727: Autocomplete should indicate that more results were found than displayed
After applying patch for d7 - nothing changed. Same behavior.
What has been used for testing:
OS Mountain Lion
Firefox 16.0.1
Safari 6.0.1
Chrome 22.0.1229.94
Comment #4
iflista commentedI should point the way I made testing.
No difference in drupal's behaviour at all.
So we need steps to reproduce issue from @Qandeel, or this is closed issue.
Comment #5
qandeel commentedI have not tested this in D8, but when you add a CSS change and add overflow:auto; and if you trim the height of the autocomplete drop down which is:
Then try to search a substring that occurs more than 6 items.. so that you can see the scroll bars on that autocomplete drop down.
I am talking about the scroll on this drop down that it appears on all the browsers but using mouse the scroll functionality only works on FF but not on Chrome and IE. In chrome and IE as soon as you click on the scroll bar to hold and scroll .. the drop down gets disappeared.
Comment #6
shabana.navas commentedI am facing the same exact problem and I am running Drupal 7, version 7.19. This issue shouldn't be taken lightly as the autocomplete is a core part of Drupal and it should work in all browsers. I have tested it with Firefox, Chrome and IE. If we limit the autocomplete size, then, the scrollbar works perfectly in FF, but just as Qandeel said, it disappears when we click the scroll bar in both Chrome and IE.
I hope this patch will go into the next core update.
Comment #7
samvel commentedSo, need change status and apply
Comment #8
Sylense commentedConfirming that this works for me. I applied the patch and CSS from the OP and it now works for me in both IE and Chrome
Comment #8.0
Sylense commentedpatch also added in comment as text
Comment #9
shameemkm commentedBack port of the patch for D7 the patch is format-patch
Comment #10
qandeel commented@shameemkm I dont get it what is the difference between the patch you created and the one that I already there??
Comment #11
shameemkm commented@Qandeel
I was just creating a backport to Drupal 7. Looks like both are same. Was your patch for 7 or 8?
Comment #12
shameemkm commented@Qandeel,
Looks like you had created a D7 patch. My mistake. My patch can be ignored or deleted.
Comment #13
mgifford9: autocomplete-overflow-1809580-9.patch queued for re-testing.
Comment #14
qandeel commented@mgifford, I dont know if I will be credited for this patch, I submitted original patch which is 100% same as the latest one only the difference is that some one just tried to name it with his own user.. In opensource its a crime to steal some one else work and put a name on it.
Comment #15
nod_Well, in any case,
$('*').click()is not ok. Drupal likes deep nested structures, this will kill performance. Use delegate or another solution.Now you can both collaborate on finding a core-worthy solution to the issue, no need to quarrel about attribution :D
Comment #16
fubhy commentedYes, wildcard selectors are not a solution. Ever.
Instead, this is actually pretty simple to fix afaik by using a little trick. It should work by simply setting the tabindex on #autocomplete to a negative value:
That *should* work.
Comment #17
mrdalesmith commentedThe suggestion in #16 isn't working for me. Anyone else got it to work?
Comment #18
mrdalesmith commentedOk, JQuery isn't one of my strong points, so I'm going to upload an amendment to the original patch so someone can tell me why it's a bad idea :)
Comment #19
acabouet commentedComment #21
mrdalesmith commentedThink that patch fail is folder structure: still not 100% clear on how a patch should be formatted. Let's try again.
Comment #22
crmn commentedi had a project where the parent wasn't a div, so the patch above didn't fixed the issue for me. added a patch not addressing exactly a div.
Comment #23
ruscoe commentedThe patch in #21 solves the problem, but the extra call to hidePopup() occasionally causes the autocomplete text field to be populated with "undefined" due to missing autocomplete data. This patch fixes that by setting the last selected element to false, allowing hidePopup() to hide the popup without attempting to add anything to the text field.
Comment #24
ruscoe commentedComment #25
crmn commentedis there a reason why the parent has to be a div again or did you simply just worked with patch #21?
patch #23 does not work for me because i have an example where the parent is a td instead of a div. (see #22)
Comment #26
ruscoe commentedNew patch to include more versatile solution from patch in #22. Thanks to @crmn.
Comment #27
mgiffordWhat are the steps to replicate this error?
Comment #28
mgiffordWhat are the steps to replicate this error?
Comment #29
zalak.addweb commented