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.
When I activate ajax for my views, and enable term autocomplete exposed filter, it looks like that form submit happens too early, when I select some option from autocomplete and hit enter. So, if I write "Пу" and the autocomplete suggests "Пушкин" and I try to select it using my keyboard arrows and enter, the form is submitted with "Пу" and throws validation error. You can reproduce it here:
http://sfera.apcards.ru/catalog
(try to type "Пу" in "Автор" field)
screenshot: http://pix.am/FOGz/
Comment | File | Size | Author |
---|---|---|---|
#21 | views-ajax-autocomplete-1264794-21.patch | 565 bytes | dsnopek |
|
Comments
Comment #1
dawehnerCan you rebuild this view on a normal english drupal installation so we could try to reproduce the bug and based on this fix the bug?
Everytime an issue is easy to reproduce the bug get's fixed much faster :)
Comment #2
restyler CreditAttribution: restyler commentedhttp://sfera.apcards.ru/test
Start to type "Ste" in "Author" and when you see "stephen king" select it using keyboard arrows, and press enter.
Comment #3
dawehnerCan you also please export the view and attach it here? Thanks!
Comment #4
restyler CreditAttribution: restyler commentedComment #5
dawehnerThe problem here is that you would have to create the fields manually and make some mistakes there as well.
Additonal this doesn't improve the motiviation to focus on this issue.
Comment #6
restyler CreditAttribution: restyler commentedI don't get your comment, sorry.
can you please re-phrase?
Comment #7
restyler CreditAttribution: restyler commentedComment #8
restyler CreditAttribution: restyler commentedjust reproduced the bug again in different situation: textfield field in node, text exposed filter + autocomplete added to the textfield by form_alter hook.
Comment #9
dawehnerSo the problem is probably that the focus is not on the autocomplete but on the actual submit element.
The prober fix would be perhaps that drupal autocomplete set's the focus manually
Comment #10
esmerel CreditAttribution: esmerel commentedComment #11
ichionid CreditAttribution: ichionid commentedHey I have the similar issue! Any update or workaround to it?
Comment #12
reeller_sk CreditAttribution: reeller_sk commentedSame issue here, I tried to add autocomplete to 'tlp_full_name_value' exposed filter in hook_form_views_exposed_form_alter, autocomplete works ok, but when I select a value from autocomplete popup and hit enter, the form is automatically submitted and the selected value isn't used. After ajax load in filter is not selected value but original value. For example I write 'adm' and autocomplete suggest in popup 'Administrator' I select this value and hit enter, after ajax load the value in filter is automatically changed back to 'adm'. I think problem is that the submit is processed before set of the selected value in the popup.
Exported view code: http://pastebin.com/Tx2Esr9k
Comment #13
reeller_sk CreditAttribution: reeller_sk commentedEdit issue settings for my comment #1264794-12: Views exposed autocomplete + ajax view = form submit happens too early.
Comment #14
pcrats33 CreditAttribution: pcrats33 commentedThere is a cTools patch that fixes this: https://www.drupal.org/node/1708438
Comment #15
Mitch Boulter CreditAttribution: Mitch Boulter commentedUnfortunately came across this issue on a project I'm currently working on. The solution I found was to call Drupal.autocompleteSubmit (in autocomplete.js) within Drupal.ajax.prototype.beforeSerialize (in ajax.js) in order to populate the textbox BEFORE the form is serialized. This solved the issue for me, but doesn't feel like an ideal solution. If anyone has a better suggestion I'm all ears.
Comment #16
akz CreditAttribution: akz commented@pcrats33: Similar problem and nice patch, but it does not fix this one.
@Drif.io is correct; the problem is a missing trigger of Drupal.autocompleteSubmit when ajax is enabled in a view. Well, autocomplete.js, binds this handler to the form submit event:
$($input[0].form).submit(Drupal.autocompleteSubmit);
However, when ajax is enabled for a view, this event is not fired, and Drupal.autocompleteSubmit should be fired for form input/button with type 'submit' click events. So, this bug can either be fixed from the autocomplete perspective (where the autocompleteSubmit should be also bound to the submit button/input click event), or from the views perspective (where form submit event should be triggered upon ajax submission). I am not sure which is the most proper solution, though, hence not providing a patch or altering the Project value of this issue.
I solved my problem, via a custom js file of my own that only does the following:
The tricky part, is that this js file should be included (therefore executed) after 'misc/autocomplete.js' and before 'views/js/*.js' files. I managed to do that by implementing hook_js_alter; I added a new entry for my custom js file with the same group and scope as 'misc/autocomplete.js' and a slightly bigger weight.
This is definitely not the ideal solution, but it feels better that overriding Drupal.ajax.prototype.beforeSerialize
Comment #17
IRuslan CreditAttribution: IRuslan as a volunteer and at DrupalJedi commentedI decided to move my version of solution into the separate ticket for Core — #2785283: Enter key press in autocomplete results lead to ajax form submission.
Maybe will be useful for someone.
Comment #18
dsnopekI can reproduce this issue too. An easy way to see it is to make a view of nodes and an exposed filter on "Author uid". If AJAX is disabled and you type "ad" and arrow key down to "admin" and press enter, the autocomplete simple injects "admin" and doesn't submit. But if AJAX is enabled, it will put "ad" into the text field and submit the form.
Comment #19
dsnopekThe CTools patch referred to in #14 doesn't actually fix this for me :-/
Comment #20
dsnopekThe core patch in #17 does work in my testing! However, getting that included in core will be tough. :-/ If there's a way to fix that on the Views end, it'd be better because it'd be easier to get it included in core
Comment #21
dsnopekHere's a patch that fixes this from Views and works in my limited testing
Comment #22
dsnopekAnd for those who are on Views 3.18 here's a re-rolled patch against the last release, since the current -dev changes how the code in the patched file is indented.
However, don't review/merge this patch! Review/merge the one on #21!
Comment #23
joseph.olstadreviewed code, looks good.
Comment #24
nickonom CreditAttribution: nickonom commentedOn Views 7.x-3.18 the patch has given:
Also after manually applying the patch it didn't fix the problem for me, so probably my use case is different.
Comment #25
joseph.olstad@nickonom try this instead:
download/copy the patch file into the views folder and then:
patch -p1 --dry-run < views-ajax-autocomplete-1264794-21.patch
if the --dry-run works (test applying the patch)
then without the --dry-run flag out and actually apply the patch as follows:
patch -p1 < views-ajax-autocomplete-1264794-21.patch
Comment #26
dsnopek@nickonom was trying with Views 3.18, for which there is a different patch on #22! That one should apply cleanly.
Comment #28
DamienMcKennaCommitted. Thanks all.
Comment #29
joseph.olstadComment #31
semanthis CreditAttribution: semanthis commentedSince that change https://www.drupal.org/project/search_api_autocomplete does not work anymore. I have not fully understood why. Maybe someone can give me a hint how to fix.
Comment #32
joseph.olstad@semanthis to revert the commit locally, run the above patch in reverse (using the -R flag)
or if you don't have wget you can use curl like this
Comment #33
semanthis CreditAttribution: semanthis commentedThank you, joseph.olstad that's what I did. I wrote a ticket for Search API autocomplete, the solution has to happen there. I just have not time at the moment to digg too deep into the problem, so I just reverted the commit.
Comment #34
joseph.olstadComment #35
joseph.olstadalready was referenced, so removing extra reference, link here:
#2977790: Since Views 3.20 Autocomplete does not work with ajax-views
Comment #36
Solthun CreditAttribution: Solthun commentedI know this issue is merged and closed, but I want to leave a warning here for anyone trying to override how autocomplete selects or submit work.
Please check https://www.drupal.org/project/drupal/issues/309088#comment-12790476