A field for creating and editing multiple records in a single form.
PHP JavaScript CSS Scheme
Latest commit be196f3 Feb 1, 2017 Jake Bentvelzen fix(MultiRecordField_actions): Minor bug in CSS, used -after postfix …
…for both "before" and "after" actions.

README.md

Multi Record Field

A drop-in replacement for GridField. Allows creating and editing multiple records in a backend or frontend form.

Supports

  • SilverStripe 3.2 and up
  • Display Logic
  • Dropzone Module
  • Quick Add New Module

Example Use

class Page extends SiteTree {
    private static $has_many = array(
        'Cells'      => 'BasicContent',
    );

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();

        $editor = MultiRecordField::create('ContentCellEditor', 'Content Cells', $this->Cells());
        $fields->addFieldToTab('Root.ContentCells', $editor);

        return $fields;
    }
}

MultiRecordField Nesting

The MultiRecordField supports nesting of other MultiRecordFields. When the field detects a MultiRecordField in the set of fields to edit, that field is added as another nested toggle field inside the parent set of fields for editing.

*Transform existing GridField into MultiRecordField *

You may want to retain a few configurations made to the GridField that MultiRecordField supports. In that case, you'll want to utilize the MultiRecordTransformation class.

This will ensure the properties on GridFieldExtensions GridFieldAddNewMultiClass will carry across.

<?php

foreach ($fields->dataFields() as $field) {
    if ($field instanceof GridField) {
        $fields->replaceField($field->getName(), $field->transform(new MultiRecordTransformation));
    }
}

Custom fields

The MultiRecordField uses the output of getCMSFields when building the fieldlist used for editing. To provide an alternate set of fields, define a getMultiRecordFields method that returns a FieldList object.

Additionally, the MultiRecordField calls the updateMultiEditFields extension hook on the record being edited to allow extensions a chance to change the fields.

Screenshots

Alt text

To-Do

Unit Tests Backend: - Ensure all form data is restored correctly when a Form $Validator returns false - Ensure Display Logic works cleanly with this module. - Ensure permission checking works as expected. Frontend: - Test sorting, ensure correct hidden fields are updated - Test add button and AJAX response. - Test error messages / display

Maintainers

Bugtracker