PHP code example of kinglozzer / multiselectfield

1. Go to this page and download the library: Download kinglozzer/multiselectfield library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kinglozzer / multiselectfield example snippets


use Kinglozzer\MultiSelectField\Forms\MultiSelectField;

class Department extends DataObject
{
    private static $db = [
        'Name' => 'Varchar',
    ];

    private static $many_many = [
        'StaffMembers' => 'StaffMember',
    ];

    private static $many_many_extraFields = [
        'StaffMembers' => [
            'Sort' => 'Int',
        ]
    ];

    /**
     * @return FieldList
     */
    public function getCMSFields()
    {
        $fields = FieldList::create();

        $staffField = MultiSelectField::create('StaffMembers', 'Staff members', $this, 'Sort');
        $fields->addFieldToTab('Root.Main', $staffField);

        return $fields;
    }
}

class StaffMember extends DataObject
{
    private static $db = [
        'Name' => 'Varchar',
    ];

    private static $many_many = [
        'Departments' => 'Department',
    ];
}