silverstripe-gridfield-betterbuttons icon indicating copy to clipboard operation
silverstripe-gridfield-betterbuttons copied to clipboard

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

Open priyashantha opened this issue 8 years ago • 1 comments
trafficstars

$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 avatar Jun 21 '17 04:06 priyashantha

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

priyashantha avatar Jun 21 '17 05:06 priyashantha