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 the user hits the return key whilst the cursor is focused on an exposed filter, the form will submit to the default form action, rather than using AJAX - if the view doesn't have a path, the exposed filter will submit the form to "/"
This can be reproduced in Chrome on views with these settings:
- Autosubmit : on
- Hide submit button : on
Chrome ignores JavaScript events attached to a hidden (CSS: display: none;) submit button, and will use the default form action
This issue applies to the media module (see #1319528: Media browser view library exposed form submit problem)
Comment | File | Size | Author |
---|---|---|---|
#1 | auto_submit_prevent_default_form_submit-1762098-1.patch | 804 bytes | davidgrayston |
Comments
Comment #1
davidgrayston CreditAttribution: davidgrayston commentedThe attached patch will prevent the default action of an auto-submit form if the view is using AJAX and has the submit button hidden. It will then submit the form using the ".ctools-auto-submit-click" click event
There is probably a better way to achieve this, but hopefully this is a good starting point
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedSetting proper status so this gets reviewed.
Comment #4
davidgrayston CreditAttribution: davidgrayston commentedUpdated status so this gets reviewed (passed testing)
Comment #5
mducharme CreditAttribution: mducharme commentedIf you use the 'element-invisible' css instead of setting a display: none property then the expected behaviour works. This is a suitable workaround imho.
Comment #6
steeph CreditAttribution: steeph commentedThe patch works well for me. Thanks!
(Is this enough to set it to RTBC? I'm kind of new so I don't know if more should test it.)
Comment #7
davidsheart02 CreditAttribution: davidsheart02 commentedI attempted to use this patch with D 7.32. It applied cleanly but did not prevent the enter key from performing the default action of submitting the form for me. The submit action is never triggered thus the underlying code never runs. I can confirm that this issue does not occur in FF. It is present in Chrome and IE11. Any thoughts on an updated patch that addresses these browsers?
Comment #9
quotesBro CreditAttribution: quotesBro commentedComment #10
abhij89 CreditAttribution: abhij89 commentedHi,
I did updated the module based on the suggestion that it has update. And since i have updated the module, the exposed filters are not working properly, ajax submission is gone, and form is submitting using get method. Since the action of the form is set to "/", hence resulting in non-functioning of filters, how to overcome this, any idea? I tried to apply the patch but it doesn't seems to be working either.
Comment #12
abhij89 CreditAttribution: abhij89 commentedComment #13
quotesBro CreditAttribution: quotesBro commented@abhij89, I guess your problem caused by update to Views 7.x-3.10.
In views/js/ajax_view.js change
this.$exposed_form = this.$view.children('.view-filters').children('form');
back to
this.$exposed_form = $('form#views-exposed-form-'+ settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-'));
(see https://www.drupal.org/node/1809958#comment-9235493)
Comment #14
quotesBro CreditAttribution: quotesBro commentedComment #15
abhij89 CreditAttribution: abhij89 commentedThanks @dberror it worked.