2017 © Pedro Peláez
 

silverstripe-vendormodule silverstripe-manyfield

SilverStripe FormField for adding dynamic data to forms.

image

fullscreeninteractive/silverstripe-manyfield

SilverStripe FormField for adding dynamic data to forms.

  • Wednesday, July 4, 2018
  • by wilr
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SilverStripe Many Field

Version License, (*1)

A reusable approach to a form field which allows you to create and delete rows in either custom built forms or in Userforms., (*2)

This is designed to work on the front-end with limited javascript (i.e it does not require GridField or entwine)., (*3)

Each row can relate to a DataObject subclass or simply to be used to capture the data as an array., (*4)

Installation

composer require fullscreeninteractive/silverstripe-manyfield

Usage

Image of Function, (*5)

use FullscreenInteractive\ManyField\ManyField;

$fields = new FieldList(
    $many = ManyField::create('SwabList', [
        TextField::create('Swab'),
        TextField::create('TestSite'),
        TextField::create('Description'),
        TextField::create('Material')
    ])
);

Data will either be saved as setSwabList($data), SwabList database field or in the SwabList relation. If you are saving into a relation such as HasMany or ManyMany list then make sure you include a hidden field in your field list., (*6)

    $many = ManyField::create('SwabList', [
        HiddenField::create('ID', ''),
        TextField::create('Swab'),
        TextField::create('TestSite'),
        TextField::create('Description'),
        TextField::create('Material')
    ]);

Sorting

Include a Hidden field Sort and make sure sorting is enabled., (*7)

    $many = ManyField::create('SwabList', [
        HiddenField::create('ID', ''),
        HiddenField::create('Sort', ''),
        TextField::create('TestSite')
    ])->setCanSort(true);

Required Fields

$many = ManyField::create('SwabList', [
    TextField::create('TestSite')->setRequired(true)
])->setCanSort(true);

Javascript Events

If you have UI handlers that need to run when fields are added or removed (such as Date Pickers) create a handler on your <body> element and listen for either:, (*8)

  • manyFieldAdded
  • manyFieldRemoved

FAQ

When I use this with File fields I don't get files uploaded?

Make sure your form encoding is set to the correct MIME type., (*9)

$form->setEncType(Form::ENC_TYPE_MULTIPART);

Licence

BSD 3-Clause License, (*10)

The Versions

04/07 2018

dev-master

9999999-dev http://silverstripe.org

SilverStripe FormField for adding dynamic data to forms.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

silverstripe versioned