Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

GridField HTML fragment 'buttons-after-left' was given content, but not defined


Go to End


1392 Views

Avatar
fireincairo

Community Member, 4 Posts

8 December 2014 at 7:49pm

Edited: 08/12/2014 7:52pm

Ok I ran into that issue, couldn't find any clue on the forum but eventually managed to fix it. Hope this can save time to anyone having the same problem.

I have a form that I instantiate in the getEditForm() method of the ModelAdmin class. That form shows a list of DataObject using the very handy GridField, and I wanted to have an "Add New" button, located after the GridField on the left (instead of the default location, which is before on the left) :

$list = $this->getList();
$fieldConfig = GridFieldConfig_RecordViewer::create();
$fieldConfig->addComponent(new GridFieldAddNewButton('buttons-after-left'));
$gridField = new GridField($this->modelClass, false, $list, $fieldConfig);

but for some reason, I was stuck with the following error message :
GridField HTML fragment 'buttons-after-left' was given content, but not defined. Perhaps there is a supporting GridField component you need to add

SOLUTION
The solution for this might seem straightforward for some people, but it wasn't for me.
You actually need to add a component GridFieldButtonRow in the GridField configuration object before adding your button in the 'button-after-left' fragment :

$list = $this->getList();
$fieldConfig = GridFieldConfig_RecordViewer::create();
$fieldConfig->addComponent(new GridFieldButtonRow('after'));
$fieldConfig->addComponent(new GridFieldAddNewButton('buttons-after-left'));
$gridField = new GridField($this->modelClass, false, $list, $fieldConfig);

Hope that helps