zendscaffolding icon indicating copy to clipboard operation
zendscaffolding copied to clipboard

Filtering for fields with fieldType "checkbox"

Open k-risc opened this issue 13 years ago • 0 comments

I use the Scaffolding class for a couple of tables. In the particular case we have a table that - amongst other fields - has three tinyint fields, and I set their fieldType to "checkbox".

Now when I use the filter form there is no way to let the search mechanisum filter according to the setting of one specific checkbox and ignore the others.

Let's say I have a column "active" in the table, and a column "admin", both tinyint fields that I use as boolean values.

Now I want to filter for active users, therefore I check the appropriate checkbox, but leave the box for "admin" unchecked. The filteres results will only be those active users that are not admin. There is no way to filter for all active users, regardless of whether they are an admin or not.

Of course this is not a bug, but more conceptual problem. I researched the code a little bit.

In the indexAction there is:

        $filterFields = $searchForm->getValues();
…
foreach ($filterFields as $field => $value) {
    if ($value || is_numeric($value)) {

Text input fields that are empty are not stored into $filterFields by getValues() and therefore such a text field is ignored when building the $select's where clause.

But getValues() delivers either true or false (or 1 or 0) for checkbox elements. There is apparently no way to have such a value excluded from $filterFields (please correct me if I am wrong).

If I ommit the fieldType of those tinyint fields, their form elements default to text input fields in both the filter and the edit form. Leaving such a field blank would force the field not to be used when constructing the where clause. But that of course allowes the user to enter arbitrary text and by thus is not user friendly at all.

I guess a solution for me would be if every field with fieldType "checkbox" would in the ilter form have an additional checkbox saying "use this field" or something. If I uncheck that checkbox, the field will not be included in the where clause.

This requires code adjustments that are hard to perform in a derived class because the original code uses a lot of the private functions which I would have to copy also to the derived class.

I am wondering if anybody else had the same problem so far and what they are thinking about it.

best regards

Christian Kirchhoff

k-risc avatar Sep 25 '12 12:09 k-risc