silverstripe-dependentdropdownfield icon indicating copy to clipboard operation
silverstripe-dependentdropdownfield copied to clipboard

Compatibility with ModelAdmin filters and $searchable_fields

Open HARVS1789UK opened this issue 6 years ago • 0 comments

@sheadawson thanks for the great module, I am finding it pretty easy to get along with and am using it within a number of GridField_ItemEditForms successfully.

I am also trying to make use of it as a filter field to search through results in the list of a GridField using the searchableFields() method (defined on DataObject) on a class of my own (a sub-class of DataObject). For example:

    public function searchableFields() {
        $callback = function($value) {
            return DataObject::get($value)->map('ID', 'getTitle');
        };
        $sourceClassField = DropdownField::create('SourceClass')
            ->setTitle('Source Object Type')
            ->setSource(static::$enabled_classes);
        $sourceIdField = DependentDropdownField::create(
            'SourceID',
            'Source Object Instance',
            $callback
        )->setDepends($sourceClassField);

       return array(
            'SourceClass' => array(
                'filter'    => 'ExactMatchFilter',
                'field'     => $sourceClassField,
                'title'     => 'Source Object Type'
            ),
            'SourceID' => array(
                'filter'    => 'ExactMatchFilter',
                'field'     => $sourceIdField,
                'title'     => 'Source Object Instance'
            )
        );
    }

This makes a request to:

http://jbba.joeharvey.local:8080/admin/payments/CreditTransaction/field/q[DestinationID]/load?val=Fixture which returns a HTTP 404 Not Found and the response Action 'field' isn't available on class PaymentAdmin..

This suggests to me that the field type/module isn't supported in the context of ModelAdmin search fields, is that right or am I doing something wrong?

If that is accurate, would this be functionality you'd be willing to add?

Thanks in advance,

HARVS1789UK

HARVS1789UK avatar Aug 28 '18 15:08 HARVS1789UK