Problem/Motivation

When the Views exposed form gets a validation error, the reset button stop working.

Steps to reproduce

  • In a clean Umami install
  • Create a node view
  • Add an exposed author filter
  • Add a reset button to the exposed form
  • Go to the view page
  • Filter on a non-existing user name
  • See an error
  • Press reset
  • See the name still filled in and the error still on the page

Proposed resolution

Skip validation when using the reset button.

Remaining tasks

Find a good fix.

User interface changes

API changes

Data model changes

Release notes snippet

Original report by @benjamin.merkley

Found this by,
Using a relationship to the "user" you can receive an autocomplete filter, add a reset button, you began to type something incorrectly and hit enter it will provide you with an error, hit reset, It will not fire because the autocomplete wasn't correct.

Tested on Simply test, with just core.

CommentFileSizeAuthor
#33 interdiff_28-33.txt885 bytesDYdave
#33 2833223-33-core-autocomplete-filter-stops-reset-button-from-firing-warning-messages.patch3.88 KBDYdave
#32 interdiff_28-29.txt701 bytesDYdave
#32 2833223-29-core-autocomplete-filter-stops-reset-button-from-firing-warning-messages.patch16.63 KBDYdave
#32 2833223-29-core-autocomplete-filter-stops-reset-button-from-firing-warning-messages1a.jpg84.92 KBDYdave
#28 2833223-28.patch3.01 KBLendude
#28 2833223-TEST-ONLY.patch1.85 KBLendude
#27 2833223-27.patch1.4 KBAkram Khan
#26 2833223-26.patch1.4 KBAkram Khan
#22 interdiff-2833223-19_21.txt747 bytesAnchal_gupta
#22 2833223-21.patch1.12 KBAnchal_gupta
#21 interdiff_19-21.txt1.32 KBasad_ahmed
#21 2833223-21.patch1.98 KBasad_ahmed
#19 interdiff_13-19.txt1.01 KBRatan Priya
#19 2833223-19.patch765 bytesRatan Priya
#16 2833223_after_patch.mp4200.72 KBAbhijith S
#16 2833223-before_patch.mp4324.05 KBAbhijith S
#13 View-autocomplete-reset-2833223-14.patch849 bytesarunkumark
#13 View-autocomplete-reset-2833223-14-D10.patch849 bytesarunkumark

Issue fork drupal-2833223

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

benjamin.merkley created an issue. See original summary.

benjamin.merkley’s picture

Title: User Autocomplete filter stops reset button from firing » Autocomplete filter stops reset button from firing
Issue tags: -contextual filter, -exposed filter +filter

Correction this has nothing to do with contextual filter, its just any autocomplete typed incorrectly will not allow the reset button to Fire

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

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

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

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.

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.

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.

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.

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.

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

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.

quietone’s picture

I was able to reproduce this on Drupal 9.4.x, standard install.

This also needs an issue summary update, see Write an issue summary for an existing issue for guidance. This is suitable as a first time issue, adding tag.

arunkumark’s picture

Created a patch to resolve the issue. Added to patches, Drupal 9.5.x support and 10.0.x support.

arunkumark’s picture

Status: Active » Needs work
arunkumark’s picture

Status: Needs work » Needs review
Abhijith S’s picture

Applied patch #13 and it fixes the issue.

RTBC +1

Anjali Rathod’s picture

Status: Needs review » Reviewed & tested by the community

Applied the patch, it works! Thanks @arunkumark .Marking it as RTBC.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Reading the issue summary and seeing the video makes me think we can add an automated test for this using WebdriverTestBase.

Also the issue summary update requested by @quietone has not been done yet.

+++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php
@@ -279,6 +279,9 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
+    if (!$form_state->isValueEmpty('op') && $form_state->getValue('op') == $this->options['reset_button_label']) {
+      $form_state->clearErrors();
+    }
     if ($pager_plugin = $form_state->get('pager_plugin')) {
       $pager_plugin->exposedFormValidate($form, $form_state);
     }

Let's do $form_state->getValue('op') === $this->options['reset_button_label']

Also I would have thought this should come after the pager plugin validations.

So it can clear any errors set there. Or maybe the pager plugin should be an elseif.

Ratan Priya’s picture

Status: Needs work » Needs review
FileSize
765 bytes
1.01 KB

@alexpott,
Made changes as per comment #18.
Needs review.

alexpott’s picture

Status: Needs review » Needs work

I think actually we can use the FormAPI to help us here... see #3165010: Using the layout builder discard changes button should ignore any input and skip validation for something similar.

I think this might be fixable by changing the reset button render array in \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase::exposedFormAlter() to

      $form['actions']['reset'] = [
        '#value' => $this->options['reset_button_label'],
        '#type' => 'submit',
        '#weight' => 10,
        // Reset is not dependent on form input.
        '#limit_validation_errors' => [],
      ];

ie... add:

        // Reset is not dependent on form input.
        '#limit_validation_errors' => [],
asad_ahmed’s picture

Status: Needs work » Needs review
FileSize
1.98 KB
1.32 KB

Made changes as per #20, needs review. Thanks

Anchal_gupta’s picture

I have uploaded the patch and addressed #20

The last submitted patch, 21: 2833223-21.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 22: 2833223-21.patch, failed testing. View results

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

Akram Khan’s picture

Added patch for upgraded version 10.1.x Made changes according to comment #20

Akram Khan’s picture

Uploading updated patch as custom commands failed

Lendude’s picture

Here is a really simple test for this, doesn't need javascript, also fails in a normal browser test.

Was hoping that #limit_validation_errors would be enough here, but it is not, but the current solution in exposedFormValidate is also causing problems, so fix needs work.

Updated the IS a bit.

The last submitted patch, 28: 2833223-TEST-ONLY.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 28: 2833223-28.patch, failed testing. View results

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

DYdave’s picture

Thanks a lot everyone for raising this issue, it's greatly appreciated.

Thanks a lot @Lendude for updating the IS and patch : we've been having the exact same issue.

The patch from #28 seems to work for us, except for the warning messages popping out after resetting the form, see for example below :

Error message
Warning: Undefined array key "title" in Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput() (line 1498 of core/modules/views/src/Plugin/views/filter/FilterPluginBase.php).
Drupal\views\Plugin\views\filter\FilterPluginBase->acceptExposedInput(Array) (Line: 183)
Drupal\views\Form\ViewsExposedForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('views_exposed_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm('\Drupal\views\Form\ViewsExposedForm', Object) (Line: 134)
Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase->renderExposedForm() (Line: 1253)
Drupal\views\ViewExecutable->build() (Line: 392)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 196)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1645)
Drupal\views\ViewExecutable->executeDisplay('page_1', Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 858)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 421)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 240)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 239)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

See screenshot below :

 

Which seems to also be part of the reason the tests could have failed at #28.

If we could perhaps prevent these warning error messages, this patch could potentially become exploitable.

DYdave’s picture

Therefore, please find attached to this comment an updated patch which prevents warning messages and resets the exposed filters values:
File attached as: 2833223-33-core-autocomplete-filter-stops-reset-button-from-firing-warning-messages.patch
Interdiff: interdiff_28-33.txt

I've tested this with required and grouped filters as well and it seemed to work, but this definitely needs help reviewing and testing.

Honestly, I haven't spent more time than this, looking into finding a more appropriate solution, as suggested by @Lendude, or in the IS, trying to "Skip validation when using the reset button". So I really have no clue whether this is the right way to fix this.
I've only really tried fixing the symptoms instead of finding the root of the issue.

Therefore, we would greatly appreciate some help reviewing and testing this updated patch and more particularly whether anyone would see potential regressions or side effects introduced by the change in this patch.

Thanks in advance for your feedback and comments.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs subsystem maintainer review

It is recommended to use MRs as patches are being phased out and DrupalCi is less supported these days.

But #33 appears to have test failures.

Did not test or review.

+        options:
+          submit_button: Apply
+          reset_button: true
+          reset_button_label: Reset
+          exposed_sorts_label: 'Sort by'
+          expose_sort_order: true
+          sort_asc_label: Asc
+          sort_desc_label: Desc

If this change updates a view config we will need an upgrade path for existing sites.