mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
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:
commit
75bec8ceb2
@ -3,6 +3,7 @@
|
||||
namespace SilverStripe\UserForms\Extension;
|
||||
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\GridField\GridFieldPaginator;
|
||||
use SilverStripe\Forms\Tab;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldButtonRow;
|
||||
@ -103,7 +104,9 @@ class UserFormFieldEditorExtension extends DataExtension
|
||||
new GridFieldDeleteAction(),
|
||||
new GridFieldToolbarHeader(),
|
||||
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');
|
||||
|
@ -228,6 +228,16 @@ class EditableFormField extends DataObject
|
||||
{
|
||||
$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
|
||||
$fields->addFieldsToTab(
|
||||
'Root.Main',
|
||||
|
@ -39,6 +39,18 @@ class Validator extends RequiredFields
|
||||
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
|
||||
if (!$this->record || !$this->record->exists()) {
|
||||
return true;
|
||||
|
@ -258,7 +258,7 @@ SQL;
|
||||
$config->addComponent(new GridFieldDeleteAction());
|
||||
$config->addComponent(new GridFieldPageCount('toolbar-header-right'));
|
||||
$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($export = new GridFieldExportButton('buttons-after-left'));
|
||||
$config->addComponent($print = new GridFieldPrintButton('buttons-after-left'));
|
||||
|
Loading…
Reference in New Issue
Block a user