This topic is locked

How to trim search values before search is conducted?

4/25/2017 6:37:08 PM
PHPRunner Tips and Tricks
admin

Q: Our user paste into the search field, and if there there are trailing blanks search returns nothing. How to trim search values before search is conducted?
A: We can use Search API for this purpose. It will work with both search panel and Advanced Search. Code goes to AfterTableInit event.
In this example table name is "Cars" and field name is "Make". Change it accordingly.

$srchObj = SearchClause::getSearchObject("Cars");

$srchObj->setFieldValue("Make", trim( $srchObj->getFieldValue("Make") ));
H
headingwest 4/26/2017

Hi Sergey, where does that code go?

admin 4/27/2017

Updated the description.