When typing a node title into the "Enter the title or NID of a post:" field of the node context, selecting an autocomplete value using the keyboard and pressing the enter key, the message "Invalid node selected." is displayed. When doing the same again but using the mouse to select, no error message appears.

CommentFileSizeAuthor
#5 panels_autocomplete.patch1.15 KBxen

Comments

triversedesigns’s picture

I have the same issue with Drupal 5.10, Panels 2 Beta5 and RC1a. Still havent found any solution. Just to not use the enter key

merlinofchaos’s picture

I believe this is a problem with the autocomplete itself plus the way forms work in HTML.

In general, 'enter' means 'submit the form'. Using the 'enter' key here tries to submit the form. The autocomplete accepts that and it appears to fill in, but the form submit also fires due to the enter key being pressed, and it submits before the autocomplete has a chance to fill in the new value. Thus, you get this error.

I'm not sure there's much that can be done about this since it's using a core piece of javascript that we can't modify.

sun’s picture

I really don't like to, but I have to prove you wrong here ;)

When doing the same with Drupal's regular autocompletes, f.e. choosing the author on a regular node form, the form does not submit when selecting a value with the keyboard. autocomplete.js implements special event handling for the onKeyUp event in Drupal.jsAC.prototype.onkeyup().

xen’s picture

I've done a bit of research on this, as I really wanted an autocomplete field in a custom pane content plugin.

"In general, 'enter' means 'submit the form'. Using the 'enter' key here tries to submit the form. The autocomplete accepts that and it appears to fill in, but the form submit also fires due to the enter key being pressed, and it submits before the autocomplete has a chance to fill in the new value. Thus, you get this error."

That's basically correct, with the added twist of panels killing autocomplete.js' submit function. autocomplete.js adds a submit handler to the form containing the field which checks if has an open dropdown and closes it and suppresses normal form submission if it did.

Panels actively unsets all submit handlers on the form when it ajaxifies it, but disabling that code doesn't help, as that just makes both handlers trigger.

Ideally, panels (or perhaps rather the ajaxSubmit in jQuery) should store the submit handlers when attaching, and manually calling them in the submit handler. If any of them return false, it should break out and not submit.

The problem is that getting the original handler(s) is internal jQuery voodoo.

xen’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

This patch fixes Drupal standard #autocomplete fields. While it's not a 'proper' fix, it'll do as a interim fix until a better solution is found.

sun’s picture

Status: Needs review » Needs work

This works for modals of the display editor (panels content), but unfortunately not for modals on the context page.

xen’s picture

sun:
You sure? Does here (tested with 'Add context "Node"').

triversedesigns’s picture

Status: Needs work » Closed (fixed)

Closing due inactivity.