From 97bbbe05e2a6b8c71f955401355f8c19780505ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Fri, 31 Mar 2017 15:21:04 +0200 Subject: [PATCH] only validated filter values pass to data source callback [Closes #73] --- src/Datagrid.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Datagrid.php b/src/Datagrid.php index 9d84e70..6eabd32 100644 --- a/src/Datagrid.php +++ b/src/Datagrid.php @@ -337,11 +337,22 @@ protected function attached($presenter) protected function getData($key = null) { if (!$this->data) { + $validFilterData = []; + if ($this->filterFormFactory) { + $this['form']->isValid(); // triggers validation + foreach ($this['form']['filter']->controls as $name => $control) { + if ($control->getErrors() === []) { + $validFilterData[$name] = $control->getValue(); + } + } + $validFilterData = $this->filterFormFilter($validFilterData); + } + $onlyRow = $key !== null && $this->presenter->isAjax(); if (!$onlyRow && $this->paginator) { $itemsCount = call_user_func( $this->paginatorItemsCountCallback, - $this->filterDataSource, + $validFilterData, $this->orderColumn ? [$this->orderColumn, strtoupper($this->orderType)] : null ); @@ -353,7 +364,7 @@ protected function getData($key = null) $this->data = call_user_func( $this->dataSourceCallback, - $this->filterDataSource, + $validFilterData, $this->orderColumn ? [$this->orderColumn, strtoupper($this->orderType)] : null, $onlyRow ? null : $this->paginator );