When using an autocomplete form field in a CTools modal dialog (for example a Fieldable Panel Pane with an Entity Reference field), the position of the autocomplete result is incorrect if the user has to scroll down in the modal dialog to see the field. The results appear near the top of the modal content dialog, rather than directly below the field.

Steps to reproduce

  1. Create /modify a Fieldable Panel Pane bundle to contain an Entity Reference field.
  2. On a panel page, add a new instance of the FPP.
  3. Scroll the modal dialog down to the Entity Reference and start typing to activate the autocomplete.

Expected behavior

The autocomplete results should appear directly below the Entity Reference field.

Actual behavior

The autocomplete results appear part-way up the modal dialog content (see attached screenshot).

I've tested this on Drupal 7.x-dev in Firefox and Chrome on Ubuntu (DrupalPro).

Comments

jlapp’s picture

It appears that the autocomplete JS does not take into account the scroll position of the modal dialog. I'm attaching a patch to fix this. This patch is against 7.x-dev, but the code in question seems to be identical in 8.x-dev, so it should apply there as well.
If there is a better place to correct this or a different method, please let me know and I can create a new patch.

jlapp’s picture

Status: Active » Needs review
Madis’s picture

Ran into the same issue with a custom form's autocomplete field and can confirm that the patch works and didn't seem to break autocomplete outside modals. This problem might have to be resolved by Ctools rather than core though.

gaëlg’s picture

Status: Needs review » Reviewed & tested by the community

Yes it works. I had this problem with Scald.

nod_’s picture

Project: Drupal core » Chaos Tool Suite (ctools)
Version: 7.x-dev » 7.x-1.x-dev
Component: javascript » Modal
Status: Reviewed & tested by the community » Needs work

What #3 says. No business having javascript selecting #modal-content in core code when D7 core doesn't support modals.

The position is set in keyup event, ctools just have to add a listener on the input for a keyup event and add the offset for the scrolling. Also it should be using closest() not parents(). Something like:
$('#autocomplete').css('top': '+' + $input.closest('#modal-content').scrollTop());

tstoeckler’s picture

Closing #1947790: Core's autocomplete.js does not account for scroll offset in a CTools modal as a duplicate and uploading the patch from there here.

I'm really not a JS guy so

add a listener on the input for a keyup event and add the offset for the scrolling

scares me.

I might try something here, but some guidance would be helpful.

yesct’s picture

Is there another place in core that does what is needed in terms of the listener that we could use as a guide?

jlapp’s picture

Issue summary: View changes
StatusFileSize
new747 bytes

Here is an updated patch against CTools based on the feedback from #5.

jlapp’s picture

Status: Needs work » Needs review
Anonymous’s picture

Applied the patch in #9: works perfect, thanks.

guedressel’s picture

Applied the patch in #9: works for us too.

guedressel’s picture

Status: Needs review » Reviewed & tested by the community
japerry’s picture

Status: Reviewed & tested by the community » Needs work

This patch breaks 'add content' button when trying to add content to a panel.

Marking needs work.

Anonymous’s picture

I'm pretty sure this patch doesn't break anything, it just adjusts the css position of an autocomplete box. Didn't break anything for me anyway. Must be something else in your setup that breaks the 'add content' button.

drcolossos’s picture

I cannot see anything breaking. We applied this patch and it works as expected. Nothing breaks. Looking at the CSS that the Javascript "manipulates", I don't think that the patch is causing issues.

caschbre’s picture

We've been using this patch since it came out and have not had any issues.

jlapp’s picture

japerry, could you provide any further details on what you're seeing? The patch is still working fine for me and others - the "Add content" button works as expected for me.

japerry’s picture

Sure, here is a screencast, using the latest dev version of panels.

http://www.youtube.com/watch?v=ZCh5pHboDsk

jlapp’s picture

Thanks japerry. I see the issue now - my patch in #9 uses functions that are only available in newer versions of jQuery. The project I wrote this patch for was using jquery_update to run jQuery 1.7 and I assume the others who tested this patch were as well, so it worked in those cases. I will write an updated patch that works with the version of jQuery that ships with D7 core and post it here shortly.

jlapp’s picture

Status: Needs work » Needs review
StatusFileSize
new788 bytes

Here is an updated patch based on #9 that does not require jQuery Update / jQuery 1.7. It should work with the D7 core version of jQuery (1.4.4) or later.

japerry’s picture

Status: Needs review » Reviewed & tested by the community

Awesome! that fixes the problem for me. Marking as RTBC and committing to the sandbox.

japerry’s picture

Status: Reviewed & tested by the community » Fixed
andrewbelcher’s picture

Status: Fixed » Needs work

Unfortunately this fix actually causes problems as well. It doesn't account for the possibility of the autocomplete being contained within a positioned ancestor, in which case it ends up putting the autocomplete far too low.

andrewbelcher’s picture

Status: Needs work » Needs review
StatusFileSize
new604 bytes

Here's a patch that fixes it by checking for a positioned parent and then filtering on modals.

japerry’s picture

Status: Needs review » Fixed

(Re)Fixed! thanks for the patch and bug report.

Commit: http://drupalcode.org/project/ctools.git/commit/2a5c109

Status: Fixed » Closed (fixed)

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