When I copy and paste a value in a search field the search starts and fails if a trailing space is within the search field (could also be leading blank).
I want to fully trim the search fields before the search begins.
How can I achieve this?
Hi @marneu, thanks for reporting this
The quickest fix for now (until the next release) is to manually edit vendor/grocery-crud/enterprise/src/GroceryCrud/Core/State/StateAbstract.php around line 1301, and change:
$this->filtersAnd[$fieldName] = $fieldValue;
to:
$this->filtersAnd[$fieldName] = trim($fieldValue);
That said, this is just a workaround and not something I plan to add to the code permanently. The reason is that trimming on the PHP side would remove spaces that the user may have added on purpose — for example, someone might search for " Smith" with a leading space to specifically match a full name where Smith is the last name, not the first.
I will aim to have a proper fix for the next version as a JavaScript change: when a user pastes something into the search field, it will be trimmed automatically. This covers the most common case, while still letting users manually type a leading or trailing space if they need to. The PHP side will stay as is.
I’ll let you know once that’s ready. In the meantime, let me know if the workaround works for you
Regards,
Johnny
Unfortunately not, i guess I’m stuck on an older version it shows ‘@version 2.0.2’ within Libraries/GroceryCrud.php