unclecheese / silverstripe-gridfield-betterbuttons

Adds new form actions and buttons to the GridField detail form
GNU General Public License v2.0
80 stars 88 forks source link

ManyMany[FIELD_NAME] checkbox set field can't be saved #163

Open priyashantha opened 7 years ago

priyashantha commented 7 years ago
$detailFormFields->push(CheckboxSetField::create('ManyMany[AvailableMonths]', 'Available Months', $monthSource))

When you have pushed a many many extra field to the GridField detail form and hit the Save and close button it triggers an error

protected function saveAndRedirect($data, $form, $redirectLink) {
    $new_record = $this->owner->record->ID == 0;
    $controller = Controller::curr();
    $list = $this->owner->gridField->getList();

    if($list instanceof ManyManyList) {
    // Data is escaped in ManyManyList->add()
    $extraData = (isset($data['ManyMany'])) ? $data['ManyMany'] : null;
    } else {
    $extraData = null;
    }

    if(!$this->owner->record->canEdit()) {
    return $controller->httpError(403);
    }

    try {
    $form->saveInto($this->owner->record);
    $this->owner->record->write();
    $list->add($this->owner->record, $extraData);
    } 
    ........
}

Issue is with manipulating the $extraData. The GridFieldDetailForm_ItemRequest get that data by customising the $data['ManyMany'] but betterbuttons is not like that.

I think try{} can be done like (code snippet from GridFieldDetailForm_ItemRequest::doSave()):

$form->saveInto($this->record);
$this->record->write();
$extraData = $this->getExtraSavedData($this->record, $list);
$list->add($this->record, $extraData);

It'll be starting point to fix the issue.

priyashantha commented 7 years ago

Hi,

I've create an PR https://github.com/unclecheese/silverstripe-gridfield-betterbuttons/pull/165 for this issue. Please have a look on that when possible

Thanks