Skip to content
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

SS4.3.0. Boolean not behaving properly in searchableFields. #8691

Closed
SpiritLevel opened this issue Jan 4, 2019 · 8 comments · Fixed by #9894
Closed

SS4.3.0. Boolean not behaving properly in searchableFields. #8691

SpiritLevel opened this issue Jan 4, 2019 · 8 comments · Fixed by #9894

Comments

@SpiritLevel
Copy link
Contributor

SpiritLevel commented Jan 4, 2019

Affected Version

phpunit/phpunit 5.7.27 The PHP Unit Testing framework.
silverstripe-themes/simple 3.2.0 The SilverStripe simple theme (default SilverStripe 3 theme)
silverstripe/recipe-cms 4.3.0 SilverStripe recipe for fully featured page and asset content editing
silverstripe/recipe-plugin 1.3.0 Helper plugin to install SilverStripe recipes

Description

    public function searchableFields()
    {
        return [
            'FeaturedOnHomepage' => [
                'filter' => 'ExactMatchFilter',
                'title' => 'Featured/Not Featured',
            ]
        ];
    }

When using a Boolean FeaturedOnHomepage in searchableFields, as above,
(1) the dropdown only displays two options, "Yes" or "No", instead of three options, "Yes", "No", "Any" as it has done in prior versions of SS and which the lessons claims it should (see Lesson 13).
(2) when using the search form in the CMS, "Yes" appears as the default in the dropdown. If one does not select anything in the dropdown then a search returns records having FeaturedOnHomepage both "Yes" and "No", even though "Yes" appears to be selected, which is incorrect behaviour; it should return only those with value "Yes".
(3) If one next selects "Yes" or "No" in the dropdown, a search returns records having FeaturedOnHome either "Yes" or "No", as selected, which is the appropriate behavior.
(4) After (3), one can no longer get a list of all records; one can only get those with value "Yes" or those with value "No", ie, they are always filtered and there is no way to get back to the unfiltered list, except by reloading the page.

@maxime-rainville
Copy link
Contributor

Confirmed locally. It can be replicated with just the generic searchable_fields config flag.

    private static $searchable_fields = array(
        'SomeBooleanField'
    );

Enum are OK. SS4.2 search is OK as well.

@robbieaverill
Copy link
Contributor

Some useful background info on #8708 (duplicate issue)

@pjayme
Copy link

pjayme commented Jan 15, 2020

Can confirm, issue is still happening on SS4.5.

Current workaround:

public function scaffoldSearchFields($_params = null)
    {
        $fields = parent::scaffoldSearchFields($_params);

        $anyText = _t('SilverStripe\\ORM\\FieldType\\DBBoolean.ANY', 'Any');
        $source = [
            null => _t('SilverStripe\\ORM\\FieldType\\DBBoolean.ANY', 'Any'),
            1 => _t('SilverStripe\\ORM\\FieldType\\DBBoolean.YESANSWER', 'Yes'),
            0 => _t('SilverStripe\\ORM\\FieldType\\DBBoolean.NOANSWER', 'No')
        ];

        $field = new DropdownField('ExternalProvider', 'External Provider', $source);

        $field->setEmptyString("\($anyText\)");
        $fields->replaceField('ExternalProvider', $field);

        return $fields;
    }

@mikeyc7m
Copy link
Contributor

mikeyc7m commented May 6, 2020

need to update class DBBoolean scaffoldSearchField() and add null to the source array.

@sunnysideup
Copy link
Contributor

sunnysideup commented Mar 23, 2021

This is still an issue in 4.7.3 ...

sunnysideup added a commit to sunnysideup/silverstripe-framework that referenced this issue Mar 23, 2021
sunnysideup added a commit to sunnysideup/silverstripe-framework that referenced this issue Mar 23, 2021
@sunnysideup
Copy link
Contributor

sunnysideup commented Mar 23, 2021

Temporary fix here:
https://github.com/sunnysideup/silverstripe-yes-no-any-filter

useage:

use Sunnysideup\YesNoAnyFilter\FixBooleanSearch;

class MyDataObject extends DataObject
{

    use FixBooleanSearch;
}

I tried to fix this in the core, but I can't seem to work out why the null value gets removed from the scaffolded Dropdown.

@sunnysideup
Copy link
Contributor

#9893

@maxime-rainville
Copy link
Contributor

Fixed by #9893

Awesome work!

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

Successfully merging a pull request may close this issue.

6 participants