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.
| Comment | File | Size | Author |
|---|---|---|---|
| #46 | 2904754-46.patch | 6.09 KB | flocondetoile |
Issue fork drupal-2904754
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
Comment #2
recrit commentedThe patch attached adds a "Disable AJAX form submit" option to the ExposedFormPluginBase.php.
Comment #3
recrit commentedrolling for 8.3.x
Comment #6
recrit commentedupdated views.data_types.schema.yml with the new option "disable_ajax_submit".
Comment #7
recrit commentedUpdated "disable_ajax_submit" to boolean
Comment #9
a.milkovskyThe patch #7 for 8.4.x works for me, thank you! Using Drupal core 8.4.5.
Comment #10
alexpottWe 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.
Comment #11
recrit commentedRolling the patch for 8.5.x.
Comment #12
khiminrm commentedPatch from #11 works for me in 8.5.3.
Comment #13
flocondetoileTesting #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.
Comment #14
recrit commentedUpdated 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.
Comment #16
a.milkovskyRe-roll of #14 for 8.6.1.
Comment #17
siavash commentedHello,
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:
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
Comment #18
bendev commentedreroll for D8.8
Comment #19
andres.torres commented+1 RTBC #18 worked fine on a 8.7.X core Thanks for the hard work!
Comment #21
harishstThank 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.
Comment #22
lendudeAny way to only show this when ajax is actually enabled?
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.
Comment #24
ravi shankar karnati commented#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.
Comment #25
giuseppe87 commentedThe 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.
Comment #26
kevinn commentedHere is a working patch for 9.15
Comment #27
szeidler commentedPatch #26 unfortunately didn't provided an interdiff, but seems to work in Drupal 9.1.x
Comment #28
pcambraComment #29
pcambraAdding a related issue that changes the same line this patch is changing
Comment #30
edwardsay commentedIt 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.
Comment #32
edwardsay commentedPatch #26 is not working on 9.3.x so here is a new patch
Comment #33
ranjith_kumar_k_u commentedComment #35
ronald van belzen commentedTested #33 in combination with infinite scroll, which does require Ajax. Works correct.
Comment #38
smustgrave commentedThis 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.
Comment #39
n_nelson350 commentedApplied the updated patch with Drupal 10 compatibility. Tested for our project and it works charm.
Comment #40
manikandank03 commented@n_nelson350, thanks for the D10 patch.
#39 patch applied with the latest Drupal 10.1.1.
Comment #41
recrit commentedComment #43
recrit commentedUpdated 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".
Comment #44
recrit commentedUpdate the issue description to the new issue template.
Comment #45
recrit commentedComment #46
flocondetoileRerolled MR5923 for Drupal Core 10.5.1