-
Notifications
You must be signed in to change notification settings - Fork 15
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
Using a ChoiceType (or EnumType) with multiple / expanded set to true as a filter breaks URL generation #151
Comments
I had some time to investigate the issue, and it seems the culprit is the As a result, all checkbox values are added to the query parameters, regardless of whether they are checked or not. To address this, I added a small check inside the method to omit unchecked checkbox values. This appears to resolve the issue: class FormUtil
{
public static function getFormViewValueRecursive(FormView $view): mixed
{
$value = $view->vars['value'];
if (!empty($view->children)) {
$value = [];
foreach ($view->children as $child) {
$childValue = static::getFormViewValueRecursive($child);
// Skip unchecked checkboxes for expanded and multiple options
if ($view->vars['expanded'] && $view->vars['multiple'] && isset($child->vars['checked']) && !$child->vars['checked']) {
continue;
}
$value[$child->vars['name']] = $childValue;
}
}
return $value;
}
} Would you be interested in me creating a PR with this fix? I believe the Additionally, would you be open to a PR implementing |
Hey @j0r1s, thank you for your kind words and time! Great explanation of the issue, and reproducer repository. That is an interesting case I haven't tested before. I wonder whether there's other way to handle this situation without relying on checking the type-specific variables in its view (such as
Sure! |
Hi!
On a positive note - pagination and sorting works fine. |
Okay so, initially I assumed that we can retrieve |
Hello Kreyu,
First of all, thank you for this amazing bundle! I've been using and following it for months, and it has been incredibly helpful.
However, I’ve encountered an issue when trying to implement a
ChoiceType
orEnumType
filter withmultiple: true
andexpanded: true
. This setup seems to break URL generation in the DataTable. Specifically, every action within the DataTable appends all filter choices to the query, regardless of whether any are selected.Here’s what I’ve done:
To avoid translation errors when the filter value is an array, I had to override the filter_clear_button block as follows:
I configured the filter with these options:
Any interaction within the DataTable (e.g., sorting, pagination) results in all filter choices being appended to the query, even if none were selected.
To help debug this issue, I’ve created a small reproducer repository: https://github.com/j0r1s/datatable-choice-filter-multiple.
I’ve tried to investigate the code to identify the root cause but haven’t been able to pinpoint it yet. I’d be happy to assist further if I can!
Thank you in advance for looking into this.
The text was updated successfully, but these errors were encountered: