-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Advanced filter value lost when changing default value type #6865
Comments
Hello! Im not agree with expected results.
$filterValues['chatState'] = [
'type' => EqualOperatorType::TYPE_NOT_EQUAL,
'value' => 'archived',
]; But expects equals condition. |
Hi kirye-dev. I am not sure if I explained it right. The default filter works fine. I open the list view first time and the list is filtered correctly: |
Hm. Its incorrect usage! You must:
|
|
@kirya-dev I confirm the bug
Is a valid way to declare a default filter value. And I submit, you can notice that the So the page reload with only the And, If I want to filter back on the default value, I can't. If I write |
I think I have it. Line 712 in Sonata\AdminBundle\Admin\AbstractAdmin:
But I think it must be:
Otherwise the $filters array overwrite the property |
To me, it's more the following criteria which is wrong
We have to compare the value vs the default value |
Hm. Current and your sudgest code dident worked correctly: $data = ['id' => ['type' => 1, 'value' => 'foo']];
$data2 = ['id' => ['type' => 2]]; // from request
var_dump(
array_merge($data, $data2),
array_merge_recursive($data, $data2)
); output array(1) {
["id"]=>
array(1) {
["type"]=>
int(2)
}
}
array(1) {
["id"]=>
array(2) {
["type"]=>
array(2) {
[0]=>
int(1)
[1]=>
int(2)
}
["value"]=>
string(3) "foo"
}
} |
For the js, something like this should be done:
|
With both the JS modified and the array_merge modified I think the issue will be solved. |
No @VincentLanglet. Problem in backend only. Fronted works correctly. Its can be covered by phpunit |
Your right. Im test array_merge_recursive |
But arrays values not correctly will merged with replace |
I'm sorry, but I took one hour to test every possible cases, I take screenshot and I provide a solution. Because you disable the empty value you cannot remove a default filter.
But If I change the value from |
Im says in another words: Need submit only CHANGED filters. Empty check needed for that didnt present in defaultValues |
Do you have en example? |
And that's not what's done by the current JS.
If my default value is It's because you looking for |
@kappaj: For example a ChoiceType when you use "multiple" => "true": $parameters:
$filters:
With "array_replace_recursive" it will be:
But it must be:
I think there is no PHP function for this, because on the third depth of the array you don't want to use "recursive" anymore. You have to use something like this:
I can make PR when #6871 is merged. It will be good to test this "mergeParameters" method to define all different situations. |
You can also make a PR on the PR#6871. It will avoid us to merge a non-finished PR. |
@willemverspyck your example incorrect: any data from filters will be ignored |
You're correct @kirya-dev. I was to fast :-) But I will make an PR on the PR#6871 with some tests. |
Sorry, was struggling with the CS tests. But the PR with tests are ready! |
Environment
Sonata packages
show
Symfony packages
show
PHP version
Subject
I have a admin list view with a default filter with activated advanced filter.
Here is my code to define the filters and default filter:
show
When I change the filter type to 'equal' and press the 'Filter' the list should filter all items with chatState = 'archived'
Tested with sonata-admin verion 3.89. Have to step back to <3.86 to get old filter behavior.
Minimal repository with the bug
Steps to reproduce
Expected results
chatState = 'archived'
list?filter[chatState][type]=1&filter[chatState][value]=archived
Actual results
list?filter[chatState][type]=1
-> value is missing
The text was updated successfully, but these errors were encountered: