Problem/Motivation

Provide configuration to disable AJAX for Views exposed form submissions.
Typical Use Case: A Non-AJAX views exposed form submission with an AJAX pager. This use case is common when there are non-view related content on the page that needs to change based on the views results. Example: Facet blocks for Search API views.
Currently, if the view is enabled to "use ajax", then the form submission and pagers are setup to use AJAX.

Proposed resolution

Add a new option for "Disable AJAX form submit" to the default views exposed form plugin.

Remaining tasks

New tests for the "Disable AJAX form submit" option.

User interface changes

Admin UI changes: The views exposed form options now have an option for "Disable AJAX form submit" when the display has AJAX enabled.

API changes

None.

Data model changes

The config schema type "views_exposed_form" has a new "disable_ajax_submit" property. See changes to "core/modules/views/config/schema/views.data_types.schema.yml".

Release notes snippet

A views exposed form can now disable AJAX for the form submissions while allow other view plugins such as pagers to still use AJAX.

Issue fork drupal-2904754

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

recrit created an issue. See original summary.

recrit’s picture

Status: Active » Needs review
StatusFileSize
new3.26 KB

The patch attached adds a "Disable AJAX form submit" option to the ExposedFormPluginBase.php.

recrit’s picture

rolling for 8.3.x

Status: Needs review » Needs work
recrit’s picture

updated views.data_types.schema.yml with the new option "disable_ajax_submit".

recrit’s picture

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

a.milkovsky’s picture

Status: Needs review » Reviewed & tested by the community

The patch #7 for 8.4.x works for me, thank you! Using Drupal core 8.4.5.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We should add a test of this new functionality. Also when changing javascript files in core you need to change the es6 versions and then build the .js versions. See https://www.drupal.org/node/2815083 for more on how to do that.

recrit’s picture

Rolling the patch for 8.5.x.

khiminrm’s picture

Patch from #11 works for me in 8.5.3.

flocondetoile’s picture

Testing #11 on 8.5.3. Patch wotks fine for exposed form. But if the exposed form is displayed as a block then the patch doesn't work anymore. Because the data attribute is set then at the block attributes level which wrap the form.

recrit’s picture

Status: Needs work » Needs review
StatusFileSize
new4.53 KB

Updated patch that moves the attribute to the action buttons. This fixes the exposed forms in a block. If any button does NOT have the attribute then the form will be setup for AJAX in Drupal.views.ajaxView.prototype.attachExposedFormAjax.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

a.milkovsky’s picture

Re-roll of #14 for 8.6.1.

siavash’s picture

Hello,

Thanks for this, it's a great functionality to have!

This didn't work for me at first, it seems like removing the contents of attachExposedFormAjax function doesn't stop the ajax from firing. However, if I realized if I comment out the line above attachExposedFormAjax where it's being applied to the form, I can successfully stop the ajax. So for now I just did this:

if(!$('[data-views-ajax-submit-disabled]')){
      this.$exposed_form.once('exposed-form').each($.proxy(this.attachExposedFormAjax, this));
    };

It's not the best obviously because it stops all ajax forms even if there is 1 disabled instance of exposed filter on the page, but wanted to share my findings.

I'm using an ajax enabled view with exposed filter as a block on the view page. It includes a text search by search API with autocomplete enabled.

Thanks again, this was very helpful!

Sia

bendev’s picture

reroll for D8.8

andres.torres’s picture

+1 RTBC #18 worked fine on a 8.7.X core Thanks for the hard work!

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

harishst’s picture

Thank you so much for this patch.

Working Excellent in Drupal 8.8.2.

I was using Search API Module and an Exposed form is created via Views for search.
For Pagination I was using Views Infinite Scroll module with Ajax.
I was unable to get the keyword from URL since once the search page is reached every request from the exposed form is Ajax driven.
Now, with this patch I could disable the Ajax on the Exposed Form.

Thank You.

lendude’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs upgrade path, +Needs upgrade path tests
  1. +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php
    @@ -47,6 +49,13 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    +    $form['disable_ajax_submit'] = [
    

    Any way to only show this when ajax is actually enabled?

  2. +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php
    @@ -269,6 +278,14 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
    +    if (!empty($this->options['disable_ajax_submit'])) {
    

    Should we also only add this when ajax is actually enabled?

Per #10, this needs tests. Also this needs an upgrade path because we are adding new config and a test for that upgrade.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ravi shankar karnati’s picture

#18 worked fine to disable the ajax for the exposed form, but can we able to disable the ajax submit for the facets ?

Example: Am using the facets block with check-box, when i clicked on any facets , ajax loading is happening, i need the page load , so likes to disable the ajax for the facets block but not to the search view. So is there any HOOK or way to handle this?

Note: using the Facet blocks module for the facets block display.

giuseppe87’s picture

The patch on D9 doesn't work.
It isn't just that doesn't apply, I've reroll-ed to get it applied but it does nothing: even if I configure the options in the view configuration, the views keep to refresh via ajax if I submit the exposed filters form.

kevinn’s picture

Here is a working patch for 9.15

szeidler’s picture

Patch #26 unfortunately didn't provided an interdiff, but seems to work in Drupal 9.1.x

pcambra’s picture

Status: Needs work » Needs review
pcambra’s picture

Adding a related issue that changes the same line this patch is changing

edwardsay’s picture

It could be important to note that actions should be performed in exact order to make this patch work:
- Add exposed filters
- Enable 'Disable AJAX form submit' option in exposed form settings
- Add pager
- And only as last action enable 'Use AJAX' option
At least for me, it worked only this way.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

edwardsay’s picture

Patch #26 is not working on 9.3.x so here is a new patch

ranjith_kumar_k_u’s picture

StatusFileSize
new4.15 KB
new282 bytes

Version: 9.2.x-dev » 9.3.x-dev
ronald van belzen’s picture

Tested #33 in combination with infinite scroll, which does require Ajax. Works correct.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Did not test

But a never of additional changes needed per #22

Also could use an issue summary update following the default template.

n_nelson350’s picture

StatusFileSize
new3.34 KB

Applied the updated patch with Drupal 10 compatibility. Tested for our project and it works charm.

manikandank03’s picture

@n_nelson350, thanks for the D10 patch.
#39 patch applied with the latest Drupal 10.1.1.

recrit’s picture

Updated this issue to 11.x with the MR 5923.
The MR has the following:
1. The latest patch from #39.
2. Added the suggestions from #22:
-- The new "Disable AJAX form submit" option is only shown when the display has AJAX enabled.
-- The attribute "data-views-ajax-submit-disabled" is only added when the display has AJAX enabled and the new option is enabled.
-- Added an post_update to populate the configuration of all views.

Pending: New tests for option "Disable AJAX form submit".

recrit’s picture

Issue summary: View changes

Update the issue description to the new issue template.

recrit’s picture

Issue summary: View changes
flocondetoile’s picture

StatusFileSize
new6.09 KB

Rerolled MR5923 for Drupal Core 10.5.1

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.