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
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.
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.
Some useful background info on https://github.com/silverstripe/silverstripe-framework/issues/8708 (duplicate issue)
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;
}
need to update class DBBoolean scaffoldSearchField() and add null to the source array.
This is still an issue in 4.7.3 ...
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.
Fixed by https://github.com/silverstripe/silverstripe-framework/pull/9893
Awesome work!
Most helpful comment
Can confirm, issue is still happening on SS4.5.
Current workaround: