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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidgrayston’s picture

The 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

merlinofchaos’s picture

Status: Active » Needs review

Setting proper status so this gets reviewed.

Status: Needs review » Needs work

The last submitted patch, auto_submit_prevent_default_form_submit-1762098-1.patch, failed testing.

davidgrayston’s picture

Status: Needs work » Needs review

Updated status so this gets reviewed (passed testing)

mducharme’s picture

If you use the 'element-invisible' css instead of setting a display: none property then the expected behaviour works. This is a suitable workaround imho.

steeph’s picture

The 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.)

davidsheart02’s picture

Issue summary: View changes

I 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?

quotesBro’s picture

Status: Needs review » Needs work
abhij89’s picture

Hi,

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.

Status: Needs work » Needs review
abhij89’s picture

Priority: Normal » Major
Status: Needs review » Needs work
quotesBro’s picture

@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)

quotesBro’s picture

Priority: Major » Normal
abhij89’s picture

Thanks @dberror it worked.