1. Go to this page and download the library: Download silverware/select2 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/ */
$field->setConfig('maximum-input-length', 20); // this will work
$field->setConfig('maximumInputLength', 20); // this will NOT work
use SilverWare\Select2\Forms\Select2AjaxField;
$field = Select2AjaxField::create(
'MySelect2AjaxField',
'Select2 Ajax Field'
);
$field->setDataClass(SiteTree::class); // by default, the field searches for SiteTree records
$field->setIDField('ID'); // the name of the field which identifies the record
$field->setTextField('Title'); // the name of the field to use for the option text
$field->setSearchFields([
'Title' // an array of fields to search based on the entered term
]);
$field->setSortBy([
'Title' => 'ASC' // an array which defines the sort order of the results
]);
$field->setLimit(256); // the maximum number of records to return
$field->setExclude([
'Title:ExactMatch' => 'Hide This Title'
]);