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.
Comment | File | Size | Author |
---|---|---|---|
#33 | interdiff_28-33.txt | 885 bytes | DYdave |
#33 | 2833223-33-core-autocomplete-filter-stops-reset-button-from-firing-warning-messages.patch | 3.88 KB | DYdave |
#28 | 2833223-28.patch | 3.01 KB | Lendude |
#28 | 2833223-TEST-ONLY.patch | 1.85 KB | Lendude |
#27 | 2833223-27.patch | 1.4 KB | Akram Khan |
Issue fork drupal-2833223
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
benjamin.merkley CreditAttribution: benjamin.merkley at Portage CyberTech commentedCorrection this has nothing to do with contextual filter, its just any autocomplete typed incorrectly will not allow the reset button to Fire
Comment #12
quietone CreditAttribution: quietone at PreviousNext commentedI 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.
Comment #13
arunkumarkCreated a patch to resolve the issue. Added to patches, Drupal 9.5.x support and 10.0.x support.
Comment #14
arunkumarkComment #15
arunkumarkComment #16
Abhijith S CreditAttribution: Abhijith S as a volunteer and at Zyxware Technologies commentedApplied patch #13 and it fixes the issue.
RTBC +1
Comment #17
Anjali RathodApplied the patch, it works! Thanks @arunkumark .Marking it as RTBC.
Comment #18
alexpottReading 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.
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.
Comment #19
Ratan Priya CreditAttribution: Ratan Priya at OpenSense Labs for DrupalFit commented@alexpott,
Made changes as per comment #18.
Needs review.
Comment #20
alexpottI 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
ie... add:
Comment #21
asad_ahmed CreditAttribution: asad_ahmed at OpenSense Labs commentedMade changes as per #20, needs review. Thanks
Comment #22
Anchal_gupta CreditAttribution: Anchal_gupta at Srijan | A Material+ Company for Drupal India Association commentedI have uploaded the patch and addressed #20
Comment #26
Akram KhanAdded patch for upgraded version 10.1.x Made changes according to comment #20
Comment #27
Akram KhanUploading updated patch as custom commands failed
Comment #28
LendudeHere 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.
Comment #32
DYdave CreditAttribution: DYdave at Code Enigma commentedThanks 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 :
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.
Comment #33
DYdave CreditAttribution: DYdave at Code Enigma commentedTherefore, 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.
Comment #34
smustgrave CreditAttribution: smustgrave at Mobomo commentedIt 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.
If this change updates a view config we will need an upgrade path for existing sites.