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.
This is especially true on views, but the first time the enter key is pressed it clears the drop down options and then the second time submits the form, the javascript needs to be a little more aggressive about submitting the form when enter is pressed and submit the form anytime the enter key is pressed and the form OR dropdown has focus.
Comments
Comment #1
drunken monkeyI think you are talking about autocomplete, not the base Search API module?
Anyways, this is a flaw in the autocomplete code in core, little we can do about that (except implement autocompletion all over again).
Comment #2
micheas CreditAttribution: micheas commentedI am using the search api module, and the form works as expected when I a use the ajax search of the form.
If I understand correctly, then the bug would be part of the core autocomplete and that is where to look for a solution to the bug.
I will start looking there. Let me know if I am misunderstanding.
Comment #3
drunken monkeyYes, this is due to the core autocomplete not automatically submitting the form. However, as a form field often is only part of the form, you generally also don't want this. Having the option to add it (when creating the autocompletion in the code, via the Form API) would be a possible feature, though, I guess. You could suggest that in the Drupal core issue queue.
Comment #5
BarisW CreditAttribution: BarisW commentedSee #309088: In autocomplete textfield, have to hit enter once to accept autocomplete, another time to submit form
Comment #6
gittosj CreditAttribution: gittosj commentedI think this is a critically important issue - I'm marking it accordingly & not something we should be using core hack workarounds to fix.
Its a major problem because:
1) User selects choice from autocomplete dropdown and hits return
2) Nothing happens - no code, guide or error message gives any feedback
3) User concludes site is useless or borked and goes elsewhere
The user's behaviour is entirely consistent and sensible - there's no autocomplete search I've seen which expects the users to hit return twice - try Google for example or even Bing - they spend millions on user testing and interface design and they use / require one submit / return to produce results.
Would it be possible it include the JS override from here: http://drupal.org/node/309088#comment-5231542 into this module or does some other solution work better? Happy to offer my time on testing / usability but no ability with code I'm afraid!
Comment #7
gittosj CreditAttribution: gittosj commentedFor the moment, I've disabled autocomplete since I can't get any of the javascript core overrides to work but keen to help debug and testing if there is a patch. Apache Solr autocomplete does not seem to have the same issue but I like search_api a lot - lot of advantages despite this issue...
Comment #8
drunken monkeyThanks for the link, with this I was able to patch this relatively quickly (although the proposed variant didn't work right away).
Please test the attached patch!
Comment #9
drunken monkeyComment #10
BarisW CreditAttribution: BarisW commentedAwesome, works just as expected. Thanks very much for fixing this.
Comment #11
BarisW CreditAttribution: BarisW commentedThomas, would you please commit this?
Comment #12
dags CreditAttribution: dags commentedI can also confirm that the patch works and was a needed fix.
Comment #13
BarisW CreditAttribution: BarisW commentedJust one check; on some sites I've applied the patch all works fine. On other sites it only works with keyboard navigation. When I click on a given word in the dropdown with my mouse, no form submit is done.
Not sure what causes this, will let you know if I manage to resolve this.
Comment #14
gittosj CreditAttribution: gittosj commentedThanks DM and sorry for the delay in testing - been away for some weeks. Patch applied fine against 7.x-1.x-dev but doesn't work for me (Drupal 7.15 and Search_Api 7.x-1.2). Can't see anything in the console / debugger to indicate why its failing - still having to keyboard submit / mouse click twice to submit the search. not sure how to give further useful feedback - any suggestions?
Comment #15
Anonymous (not verified) CreditAttribution: Anonymous commented@#14 you might try refreshing Drupal caches.
To auto_submit when mouse-clicking a keyword from the list, I did this (for submitting with Search API Ajax):
Notice that I first check that Drupal.jsAC is loaded:
if ( typeof Drupal.jsAC != 'undefined') {
Otherwise javascript breaks (in my case).
I see that the patch from #8 is for onkeyup, does it also handle the select event when mouse-clicking on a keyword?
Comment #16
gittosj CreditAttribution: gittosj commentedThanks morningtime - caches were cleared but thanks for suggestion. Added your function to search_api_autocomplete.js and mouse clicks / selections now work perfectly - thanks. Sadly keyboard submit / return still not working until second submit / return.
Comment #17
BarisW CreditAttribution: BarisW commentedWould be worth to implement this patch too: http://drupal.org/node/254477#comment-5203326
It's a core bug in the autocomplete function that when you hit search while the autocompletion hasn't finished yet, you'll get a Javascript error. This only happens with JS aggregation enabled.
By adding the following code to the search_api_autocomplete.js file, the error is gone. I've just copied the Drupal.ACDB.prototype.search function from core into your JS file and applied the patch from #254477: Javascript autocomplete does not cancel properly when clicking on a submit button.
Comment #18
BarisW CreditAttribution: BarisW commentedChanging status back before this is committed ;)
Comment #19
Andreas Radloff CreditAttribution: Andreas Radloff commentedFor this to work for me I had to add a check for Drupal.search_api_ajax since I don't use AJAX, also the class for auto submit is auto_submit for me, not auto-submit as in your script. Why is that?
Otherwise the patch and auto submit works good!
Comment #20
mErilainen CreditAttribution: mErilainen commentedI have tested all the above mentioned patches and fixes and everything works nicely! I added everything into a single patch, please review.
Comment #21
gittosj CreditAttribution: gittosj commentedTested #20 and seems to work perfectly - thank you and much appreciated. Can we commit this now?
Comment #22
Anonymous (not verified) CreditAttribution: Anonymous commented+1 from me, it works for me too.
Comment #23
deepbluesolutions CreditAttribution: deepbluesolutions commented+1 working for me too
Comment #24
gittosj CreditAttribution: gittosj commentedUpgraded to 7.16 and still works fine but now find that I'm getting a JS error popup "An AJAX HTTP request terminated abnormally" etc when hitting submit before suggestions load. Reading here:
http://drupal.org/node/1232416
... it seems clear that core JS files are still being refactored / worked on and that the patch suggested there breaks autocomplete functionality completely. Workaround is here:
http://drupal.org/node/1232416#comment-6168158
add
window.alert = function() {};
to the top of any loaded JS file and error is suppressed - not a problem since its not a real error bit might not help your debugging elsewhere
Comment #25
drunken monkey@ mErilainen: Thanks for integrating everything into one patch to test!
However, I don't think we should add these other changes. In detail:
I don't think that submitting the form when the suggestion is only clicked is intuitive. When the Enter key is pressed, yes, then I'd assume the form will be submitted. But when I just click?
You also have to take scenarios into account where the keywords field isn't the only input field and users will want to edit those as well after inputting the keywords. In this case, as a user, I'm pretty sure I'd not assume that clicking a suggestion will submit the form.
What do others say here?
Also, I don't like the style of that change at all. I'm pretty sure that should go into an object with an
attach
function.Maybe, but in a different issue, please.
Also, this bug doesn't occur for me anymore, so maybe it's been fixed in core already? #24 would also suggest that this could soon be fixed (but, strangely, that it isn't now) so we probably shouldn't interfere with core there.
Please test the attached re-rolled version of #8 and tell me if it works for the core issue here. (And, of course, also your opinion for auto-submitting when clicking.)
Comment #26
queenvictoria CreditAttribution: queenvictoria commentedFor my money I prefer the patch in #20. Reason being (in deference to @drunkenmonkey) Google submits on click (I checked--thrice). And if Google does it the user expects that behaviour everywhere. Whatever the rest of us believe. (In fact I now recall that I discarded search_api_autocomplete as a solution not two weeks ago because it *didn't* apply this behaviour).
I did test both #25 and #20. (Manually as it seems as though they don't apply cleanly?). Both work well for the "press return" function. #20 Works well for click function too. Neither seem to produce errors.
Re: the extra bits and pieces. Perhaps it isn't the right way to do things. Split them up?
I've rerolled #20 for reference.
Comment #27
gittosj CreditAttribution: gittosj commented@drunken monkey - Agree with you that the 'submit with keyboard' functionality is the key functionality here. 'Click term with mouse' function is nice but not vital. Struggled to get you latest patch to apply cleanly but #26 by @queenvictoria applies fine but works well.
If you have ajax switched on in the underlying view then you get a javascript popup (terminated abnormally etc) when you press submit / return before the autocomplete has loaded - workaround - turn off ajax on the the view for the moment.
I'd strongly support merging 'submit with keyboard' into dev - having to re-patch with each new release is getting boring!
Comment #28
exlin CreditAttribution: exlin commentedPatch doesn't work with Internet Explorer versions 9 and 10, with IE8 it works just fine.
For some reason onKeyUp doesn't get the keycode from enter on first time, meaning you need to press enter twice.
Fixed it by changing in search_api_autocomplete.js file
to
And in misc/autocomplete.js (core) file (line 48):
to
Comment #29
gittosj CreditAttribution: gittosj commentedStill can't get #25 to apply - tried manual apply but chaos! #26 still applies well and works with latest updated dev - would it be possible to submit this to latest dev?
Comment #30
checker CreditAttribution: checker commentedConfirn patch #26 works. Tested in current FF and IE 8-9
+1 submit on click
Comment #31
yechuah CreditAttribution: yechuah commentedbase 26 on 1.0-beta2
Comment #32
yechuah CreditAttribution: yechuah commentedforgot search_api_autocomplete.js
Comment #33
asak CreditAttribution: asak commented+1 for #32 - works great. +1 on the "submit on click" as well... ;)
Comment #34
drunken monkey@ yechuah: Please always create patches against the current dev version, not some year-old Beta.
@ queenvictoria: Thanks for the re-roll!
@ all: OK, if everyone else is in favor, then let's also auto-submit for clicks. I committed the patch in #26 now.
Thanks for testing and voting, everyone, and sorry I took so long for committing!
Comment #36
sgurlt CreditAttribution: sgurlt commentedI wrote a little patch that allows the users to deactivate the auto submit function. By default its activated, but the users are now able to disable it by unsetting a checkbox set is attaced to the autocomplete settings form.
Comment #37
sgurlt CreditAttribution: sgurlt commentedComment #38
drunken monkeyThanks a lot for your contribution, the patch already looks quite good. I just had a few alterations to explain the option better in the UI, and to clean up the code a bit (hopefully).
However, please don't resurrect two years old issues, especially when it's obviously about a related, but separate, feature request.
I created a new issue, please discuss there: #2493919: Add the option to disable auto-submit.
Comment #40
gauravjeet CreditAttribution: gauravjeet as a volunteer and at Srijan | A Material+ Company commentedJust a follow-up for someone looking up to this :
Drupal.jsAC.prototype.select
function from core autocomplete.js to my custom JS file under my module's behaviorthis.input.form.submit();
out of thisI didn't really touch any core file though !