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

ModelAdmin Search form MultiSelect field types submit javascript [object Object] #1840

Closed
2 tasks done
christohill opened this issue Oct 23, 2024 · 1 comment
Closed
2 tasks done

Comments

@christohill
Copy link

christohill commented Oct 23, 2024

Module version(s) affected

5.2.22

Description

When adding a multi-select field type to a ModelAdmin search form through modifying the SearchContext in GridFieldFilterHeader, the multi-select field submits an string of comma separated javascript type objects ([object Object]).

I've tested this with ListboxField and TagField (silverstripe/tagfield) with similar results. Interestingly, CheckboxSetField which is also marked as php $schemaDataType = FormField::SCHEMA_DATA_TYPE_MULTISELECT submits a string of comma separated keys when an array is set as the source.

How to reproduce

Basic example

public function getGridField(): GridField {
    $grid = parent::getGridField();
    $filter = $grid->getConfig()->getComponentByType(GridFieldFilterHeader::class);
    $context = $filter->getSearchContext($grid);
    $fields = $context->getFields();
    $fields->add(ListboxField::create('Test', 'Test', ['one' => 'One', 'two' => 'Two']));

    return $grid;
}

Form Data Payload: filter[members][Test]: [object Object],[object Object]

Custom SearchContext Example

// ModelAdmin
public function getGridFieldConfig(): GridFieldConfig {
    $config = parent::getGridFieldConfig();
    $filter = $config->getComponentByType(GridFieldFilterHeader::class);
    $filter->setSearchContext(MemberSearchContext::create(Member::class));

    return $config
}
// MemberSearchContext
class MemberSearchContext extends SearchContext {

    public function getSearchFields() {
        $fields = parent::getSearchFields();
        $fields->add(ListboxField::create('Test', 'Test',  ['one' => 'One', 'two' => 'Two']));
        return $fields;
    }

    public function getQuery($data, $sort = false, $limit = false, $existingQuery = null) {
        $query = parent::getQuery($data, $sort, $limit, $existingQuery);
        // Dump form data
        echo "<pre>";
        var_dump($data);
        echo "</pre>";
        die();
        return $query;
    }
}

Possible Solution

No response

Additional Context

image

Validations

  • Check that there isn't already an issue that reports the same bug
  • Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)
@GuySartorelli
Copy link
Member

GuySartorelli commented Oct 23, 2024

Closing as a duplicate of #1746
If this issue provides additional context, please add that context to the original issue.

@GuySartorelli GuySartorelli closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
@GuySartorelli GuySartorelli transferred this issue from silverstripe/silverstripe-framework Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants