Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Extra spaces at the start or end of text entered into an exposed filter can cause problems. For example, if you have something with "foo" and you filter for "foo" you'll get the result. But, if you filter for "foo " (note the extra space) you can get into a problem.
Either by default or via an option this should be passed through trim().
Comments
Comment #1
neoglez CreditAttribution: neoglez commentedWell yes, the question here is where to introduce the trim: in this class (wich method?) or in the exposed form plugin...
I think one should try to make it as more general as possible.
here an export to clarify:
Comment #2
dawehnerI think placing it both in views_handler_fitler::init and views_handler_filter::acceppt_exposed_input would be one solution
Another solution would be in pre_query()
Comment #3
dagmarInitial patch.
Comment #4
dawehnerWhat about using array_map for arrays?
I totally agree that this should be the default behavior, because this improves the UX.
Comment #5
DuaelFrIt looks good to me.
I integrated Daniel's advices.
Comment #6
davemaxg CreditAttribution: davemaxg commentedI'm interested in using this functionality on a production site running 7.x-3.7. Is the safest approach to apply this patch to 3.7 or just install the dev branch? I'm assuming that the next release will incorporate this feature, correct?
Thanks,
David
Comment #7
pjcdawkins CreditAttribution: pjcdawkins commentedThe patch in #5 works.
It's an excellent and simple UX improvement.
@davemaxg: Patches are usually designed to apply to -dev, but in this case the patch works against both 7.x-3.7 and the current latest 7.x-3.x-dev.
Comment #8
pjcdawkins CreditAttribution: pjcdawkins commented5: views-add_trim_option_on_string_filters-1301746-5.patch queued for re-testing.
Comment #9
SukanyaDhan CreditAttribution: SukanyaDhan commentedHi,
The patch #5 worked perfectly fine.
I would like to know if the trim feature comes by default in the Views version greater than 2.16 for Drupal 6?
Comment #10
MurzThanks, patch works very well, will be good to see it in views core.
Comment #11
colanWe've recently switched our testing from the old qa.drupal.org to DrupalCI. Because of a bug in the new system, #2623840: Views (D7) patches not being tested, older patches must be re-uploaded. On re-uploading the patch, please set the status to "Needs Review" so that the test bot will add it to its queue.
If all tests pass, change the Status back to "Reviewed & tested by the community". We'll most likely commit the patch immediately without having to go through another round of peer review.
We apologize for the trouble, and appreciate your patience.
Comment #12
colanComment #13
RdeBoerAs this patch was never added to Views and because I don't like the maintenance overhead of patched modules on my system, I wrote a mini-module that implements the functionality of the patch of #5.
It is available here: https://www.drupal.org/sandbox/rdeboer/2660818
Comment #14
pjcdawkins CreditAttribution: pjcdawkins at Centarro commentedRe-uploading the patch from #5
edit: note that the patch is by DuaelFr
Comment #15
DuaelFrThanks for reposting.
Can we reproduce in Drupal 8 ? If so, we should move this issue in the Core queue so it can be fixed using the common workflow (edge version then backport).
Comment #16
TommyK CreditAttribution: TommyK at Caltech commentedI just ran into the white space issue. I had to re-roll the patch to get it to apply to the current 7.x-3.x-dev. I did not change any of the functional content, but the line numbers significantly changed.
Comment #18
biguzis CreditAttribution: biguzis at Wunder commentedRerolled #14
Comment #19
biguzis CreditAttribution: biguzis at Wunder commentedComment #20
thetwentyseven CreditAttribution: thetwentyseven commentedComment #21
DamienMcKenna@thetwentyseven: Hello there, thanks for trying to put together that patch. However, it seems you didn't create the patch correctly as the paths start with "sites/all/modules", you might want to reread the docs on creating a patch to see if there's a step you missed. Also, what was the intention of the patch - were you rerolling it, were there intended changes on the patch itself, etc? Thanks.
Comment #22
AlbionBrown CreditAttribution: AlbionBrown commentedUpdated patch file for 7.x-3.23
Comment #23
AlbionBrown CreditAttribution: AlbionBrown commentedThat's annoying, the patch applied fine for me. Does it apply fine manually for anyone else?
Comment #24
DamienMcKennaThe paths are incorrect for the patch, they should be relative to the module directory, not the site.
I've rerolled the patch, please give this one a try.
Comment #25
AlbionBrown CreditAttribution: AlbionBrown commentedAh! I hadn't spotted that, thanks!