Tabbed forms
Silverstripe CMS's FormScaffolder can automatically generate Form instances for certain database models. In the CMS and other scaffolded interfaces, it will output TabSet and Tab objects and use jQuery Tabs to split parts of the data model.
All interfaces within the CMS such as ModelAdmin and LeftAndMain use tabbed interfaces by default.
When dealing with tabbed forms, modifying the fields in the form has a few differences. Each Tab will be given a
name, and normally they all exist under the Root
TabSet.
Adding a field to a tab
$fields->addFieldToTab('Root.Main', TextField::create(/* ... */));
Removing a field from a tab
$fields->removeFieldFromTab('Root.Main', 'Content');
Creating a new tab
$fields->addFieldToTab('Root.MyNewTab', TextField::create(/* ... */));
Moving a field between tabs
$content = $fields->dataFieldByName('Content');
$fields->removeFieldFromTab('Root.Main', 'Content');
$fields->addFieldToTab('Root.MyContent', $content);
Add multiple fields at once
$fields->addFieldsToTab('Root.Content', [
TextField::create('Name'),
TextField::create('Email'),
]);
Change the order of tabs
If you need to change the order of tabs, for example if the tabs were scaffolded through FormScaffolder
,
you can do so by passing the correct order of the tabs into TabSet::changeTabOrder()
.
If there are more tabs in the tab set than you include in the tab order, they will be added after the tabs you explicitly included.
$fields->fieldByName('Root')->changeTabOrder(['FirstTab', 'SecondTab']);