diff --git a/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_name.yml b/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_name.yml index 9bcf36b3fb..b3ae725d96 100644 --- a/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_name.yml +++ b/core/modules/user/tests/modules/user_test_views/test_views/views.view.test_user_name.yml @@ -19,6 +19,14 @@ display: type: tag exposed_form: type: basic + 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 pager: type: full row: diff --git a/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php b/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php index 5fddb8a906..1c6f8c340f 100644 --- a/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php +++ b/core/modules/user/tests/src/Functional/Views/HandlerFilterUserNameTest.php @@ -189,6 +189,16 @@ public function testExposedFilter() { foreach ($this->accounts as $account) { $this->assertSession()->pageTextContains($account->id()); } + + // Pass in an invalid username, after pressing reset the error should be + // gone. + $users = [$this->randomMachineName()]; + $users = array_map('strtolower', $users); + $options['query']['uid'] = implode(', ', $users); + $this->drupalGet($path, $options); + $this->assertSession()->pageTextContains('There are no users matching "' . implode(', ', $users) . '".'); + $this->getSession()->getPage()->pressButton('Reset'); + $this->assertSession()->pageTextNotContains('There are no users matching'); } } diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index d986a97d05..3c3e0f5c71 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -251,6 +251,7 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) { '#value' => $this->options['reset_button_label'], '#type' => 'submit', '#weight' => 10, + '#limit_validation_errors' => [], ]; // Get an array of exposed filters, keyed by identifier option. @@ -279,6 +280,9 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function exposedFormValidate(&$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); } diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index 1d24826b75..4e29fb04a6 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -1492,10 +1492,10 @@ public function acceptExposedInput($input) { if (!empty($this->options['expose']['identifier'])) { if ($this->options['is_grouped']) { - $value = $input[$this->options['group_info']['identifier']]; + $value = $input[$this->options['group_info']['identifier']] ?? NULL; } else { - $value = $input[$this->options['expose']['identifier']]; + $value = $input[$this->options['expose']['identifier']] ?? NULL; } // Various ways to check for the absence of non-required input.