Skip to content

Extends a simple Text field to have several named parts (keys).

License

Notifications You must be signed in to change notification settings

fullscreeninteractive/silverstripe-keyvaluefield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SilverStripe Key Value Field

Version License

A reusable approach to a form field which extends a simple Text field to have several named parts (keys). This module also supports User Defined Forms.

Installation

composer require fullscreeninteractive/silverstripe-keyvaluefield

Usage

Image of Function

use FullscreenInteractive\KeyValueField\KeyValueField;

$fields = new FieldList(
    KeyValueField::create('Quantity', 'Enter quantity of each size')
        ->setKeys([
            'Small',
            'Medium',
            'Large'
        ])
);

When using ORM managed forms and models (i.e saveInto) data will be saved as a serialized array of the values to each of the keys. You can change this behaviour if needed in your Form class.

public function doSave($data, $form)
{
    $quantity = $form->dataFieldByName('Quantity');

    // returns an array of key => value
    $values = json_decode($quantity->dataValue(), true);

    echo $values['Small']
}

Licence

BSD 3-Clause License

About

Extends a simple Text field to have several named parts (keys).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages