Problem/Motivation

Views in D7 had a nifty 'auto-submit' option for the basic exposed form plugin, which leveraged the small js library in Ctools with the same name.

Proposed resolution

Since Ctools 8.x probably doesn't want/need small features like this anymore, let's copy over the code and add the option in BEF.

Remaining tasks

Review the patch.

User interface changes

A new 'Autosubmit' option is added to he BEF exposed filter plugin.

API changes

Nope.

Data model changes

Nope.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amateescu created an issue. See original summary.

amateescu’s picture

Status: Active » Needs review
FileSize
6.7 KB

This should do it.

dawehner’s picture

  1. +++ b/js/auto_submit.js
    @@ -0,0 +1,105 @@
    +      // The change event bubbles so we only need to bind it to the outer form.
    ...
    +        .filter('form, select, input:not(:text, :submit)')
    +        .once('bef-auto-submit')
    +        .change(function (e) {
    +          // don't trigger on text change for full-form
    +          if ($(e.target).is(':not(:text, :submit, .bef-auto-submit-exclude)')) {
    +            triggerSubmit.call(e.target.form);
    +          }
    +        });
    

    In an ideal world I would have written an object doing that kind of stuff, rather than just putting the entire logic into an behaviour

  2. +++ b/src/Plugin/views/exposed_form/BetterExposedFilters.php
    @@ -539,6 +571,17 @@ Off|No
    +      $form = array_merge_recursive($form, array('#attributes' => array('class' => array('bef-auto-submit-full-form'))));
    +      $form['actions']['submit']['#attributes']['class'][] = 'bef-auto-submit-click';
    

    This stuff should not use classes but rather data attributes. Classes are meant for styling purposes. At least this is what core is doing now more and more.

mikeker’s picture

Status: Needs review » Needs work

Thank you for the patch, @amateescu, and the review, @dawehner!

Setting to NW based on #3. I'll try to find time this week to make those changes but will happily commit if someone beats me to it!

ABaier’s picture

Would love to see that feature also. Looking forward!

mikeker’s picture

Addresses #3.2 (moves JS interactions from classes to data attributes). Would love to have another set of eyes look/test this as I don't have the bandwidth for more complete testing at the moment.

Speaking of which, were there any automated tests for this in D7's CTools? I'm guessing not...

I'll look into #3.1 later today but I'm not opposed to committing this without that change as there are a few other BEF bits that could use a similar refactor.

dawehner’s picture

Status: Needs work » Reviewed & tested by the community

I'll look into #3.1 later today but I'm not opposed to committing this without that change as there are a few other BEF bits that could use a similar refactor.

Sure we can always do that later.
One follow up which could be open is to provide some form of javascript test coverage.

  • mikeker committed be32457 on 8.x-3.x
    Issue #2764981 by mikeker, amateescu: Add 'auto-submit' functionality to...
mikeker’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you!

mikeker’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.