Enable better button functionality (#897)

Enable better button functionality

Co-authored-by: Bram de Leeuw <bram-de-leeuw@hotmail.com>
Co-authored-by: Bram de Leeuw <bram@xd.nl>
This commit is contained in:
Guy Marriott 2019-07-16 14:09:54 +12:00 committed by GitHub
commit 75bec8ceb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 2 deletions

View File

@ -3,6 +3,7 @@
namespace SilverStripe\UserForms\Extension; namespace SilverStripe\UserForms\Extension;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\Tab; use SilverStripe\Forms\Tab;
use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldButtonRow; use SilverStripe\Forms\GridField\GridFieldButtonRow;
@ -103,7 +104,9 @@ class UserFormFieldEditorExtension extends DataExtension
new GridFieldDeleteAction(), new GridFieldDeleteAction(),
new GridFieldToolbarHeader(), new GridFieldToolbarHeader(),
new GridFieldOrderableRows('Sort'), new GridFieldOrderableRows('Sort'),
new GridFieldDetailForm(null, false, false) new GridFieldDetailForm(),
// Betterbuttons prev and next is enabled by adding a GridFieldPaginator component
new GridFieldPaginator(999)
); );
$editButton->removeExtraClass('grid-field__icon-action--hidden-on-hover'); $editButton->removeExtraClass('grid-field__icon-action--hidden-on-hover');

View File

@ -228,6 +228,16 @@ class EditableFormField extends DataObject
{ {
$fields = FieldList::create(TabSet::create('Root')); $fields = FieldList::create(TabSet::create('Root'));
// If created with (+) button
if ($this->ClassName === EditableFormField::class) {
$fieldClasses = $this->getEditableFieldClasses();
$fields->addFieldsToTab('Root.Main', [
DropdownField::create('ClassName', _t(__CLASS__.'.TYPE', 'Type'), $fieldClasses)
->setEmptyString(_t(__CLASS__ . 'TYPE_EMPTY', 'Select field type'))
]);
return $fields;
}
// Main tab // Main tab
$fields->addFieldsToTab( $fields->addFieldsToTab(
'Root.Main', 'Root.Main',

View File

@ -39,6 +39,18 @@ class Validator extends RequiredFields
return false; return false;
} }
// When the record is unsaved and the classname is not set throw an error
if ((!$this->record || !$this->record->exists()) && (!isset($data['ClassName']) || empty($data['ClassName']))) {
$this->validationError(
'ClassName',
_t(
__CLASS__ . 'CLASSNAME_ERROR',
'You need to select a field type before you can create the field'
)
);
return false;
}
// Skip unsaved records // Skip unsaved records
if (!$this->record || !$this->record->exists()) { if (!$this->record || !$this->record->exists()) {
return true; return true;

View File

@ -258,7 +258,7 @@ SQL;
$config->addComponent(new GridFieldDeleteAction()); $config->addComponent(new GridFieldDeleteAction());
$config->addComponent(new GridFieldPageCount('toolbar-header-right')); $config->addComponent(new GridFieldPageCount('toolbar-header-right'));
$config->addComponent($pagination = new GridFieldPaginator(25)); $config->addComponent($pagination = new GridFieldPaginator(25));
$config->addComponent(new GridFieldDetailForm(null, null, false)); $config->addComponent(new GridFieldDetailForm(null, true, false));
$config->addComponent(new GridFieldButtonRow('after')); $config->addComponent(new GridFieldButtonRow('after'));
$config->addComponent($export = new GridFieldExportButton('buttons-after-left')); $config->addComponent($export = new GridFieldExportButton('buttons-after-left'));
$config->addComponent($print = new GridFieldPrintButton('buttons-after-left')); $config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));