SuluFormBundle
SuluFormBundle copied to clipboard
Search in Dynamics list not working
Hi @alexander-schranz ,
this seems not to work because the request is missing searchFields
param
vendor/sulu/form-bundle/Repository/DynamicRepository.php
protected function addSearchFilter(QueryBuilder $queryBuilder, ?string $search, ?array $searchFields): void
{
if (empty($search) || empty($searchFields)) {
return;
}
It works adding &searchFields=data
to the /admin/api/form/dynamics
request
Originally posted by @simontol in https://github.com/sulu/SuluFormBundle/issues/11#issuecomment-1206529789
That is really change. Which fields=
are active in your columnOptions
? The searchParams
are filled up by all fields which you are currently activated in your Column Options
settings dropdown and are marked as searchable
. Sounds like no searchable fields are returned by the metadata 🤔
Can you check what is happening here for your form? https://github.com/sulu/SuluFormBundle/blob/4b52fdfb623e126e43b38fa0acfce3af5b0982a5/ListBuilder/DynamicListFactory.php#L68
And check if in the UI under the Settings Symbol you have activated a Column Options
which supports to be searched? Only visible column options are able to be searched.
I've tried to clean install sulu-form bundle inside the sulu-demo project and created the test form as explained in the documentation.
After that I've generated some form data and tried to search but it's not working, it always returns all the results unfiltered.
As you can see from the picture all columns except id are enabled and visible.
The request executed by the search box is:
http://127.0.0.1:8000/admin/api/form/dynamics?page=1&locale=en&form=1&limit=10&fields=salutation,title,firstName,lastName,street,zip,city,state,country,function,company,fax,phone,email,attachment,radioButtons,checkboxMultiple,dropdown,dropdownMultiple,checkbox,text,textarea,created,id&search=test&flat=true
I've debugged the request route and found that it doesn't filter the results because of this condition:
if (empty($search) || empty($searchFields)) {
return;
}
I didn't customize the DynamicListFactory.php so it seems to return searchability: 'never'
for all the fields.
As stated before adding &searchFields=data
to the request I get the expected result.
If I put somehing different than data
in searchFields
params (eg. title) i get this error:
[Semantical Error] line 0, col 80 near 'title LIKE :searchTerm0': Error: Class Sulu\\Bundle\\FormBundle\\Entity\\Dynamic has no field or association named title"
@alexander-schranz A customer just noticed this issue and I took a quick look at it.
1 - Missing parameter
As @simontol said, the request is missing the searchFields
param and only contains fields
.
With following change, the fields are correctly transmitted to the DynamicRepository
:
->get('searchFields'
➡️ ->get('fields'
.
https://github.com/sulu/SuluFormBundle/blob/2.5/Controller/DynamicController.php#L167
2 - Database query
With the 2.0.0
release the single columns have been migrated to only one data
JSON field.
That's why following change is necessary:
'dynamic.' . $searchField,
➡️ 'dynamic.data',
https://github.com/sulu/SuluFormBundle/blob/2.5/Repository/DynamicRepository.php#L136
This way it works, but the UI settings are ignored!
❓
Sadly I can't think of a nice solution to build a query with a combination of the field name and search term as that would require a combination of %
and *
due to the single data
column. Does anyone of you have an idea how to solve this in the DynamicRepository
?
@alexander-schranz Would you like me to create an Pull request with these 2 changes? Or do you have an idea how we could customize the query?
@alexander-schranz (@simontol ) I've created a pull request which fixes this issue in an easy way (ignoring the UI settings): https://github.com/sulu/SuluFormBundle/pull/375