Skip to content

Search in Dynamics list not working #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simontol opened this issue Aug 8, 2022 · 7 comments · Fixed by #375
Closed

Search in Dynamics list not working #332

simontol opened this issue Aug 8, 2022 · 7 comments · Fixed by #375
Labels

Comments

@simontol
Copy link

simontol commented Aug 8, 2022

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 #11 (comment)

@alexander-schranz
Copy link
Member

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 🤔

@alexander-schranz
Copy link
Member

Can you check what is happening here for your form?

FieldDescriptorInterface::SEARCHABILITY_NEVER,

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.

@simontol
Copy link
Author

simontol commented Aug 10, 2022

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.
immagine

@simontol
Copy link
Author

simontol commented Aug 10, 2022

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"

@thomasduenser
Copy link
Contributor

@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?

@thomasduenser
Copy link
Contributor

@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?

@thomasduenser
Copy link
Contributor

@alexander-schranz (@simontol ) I've created a pull request which fixes this issue in an easy way (ignoring the UI settings): #375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants