PHP code example of sheadawson / silverstripe-select2
1. Go to this page and download the library: Download sheadawson/silverstripe-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/ */
sheadawson / silverstripe-select2 example snippets
$field = AjaxSelect2Field::create('PageID');
// Set a class to search for. Defaults to SiteTree
$field->setConfig('classToSearch', 'MyCustomObject');
// Set a list of fields to search on. Default is Title
$field->setConfig('searchFields', array('Title', 'ID'));
// Limit the number of results loaded per page (scroll set). Default is 200
$field->setConfig('resultsLimit', 100);
// The number of characters typed before search results are displayed. Default is 2.
$field->setConfig('minimumInputLength', 3);
// Configure how items should be displayed in the results list. The value gets parsed by the template parser
// You can use HTML too. Default is '$Title'.
$field->setConfig('resultsFormat', '<strong>$Title</strong><br />$AbsuluteLink');
// Configure how the currently selected item should be displayed. Default is '$Title'.
$field->setConfig('selectionFormat', '$Title ($ClassName)');
// Configure the text displayed when no item is selected. Default is 'Search...'
$field->setConfig('placeholder', 'Search for a Page...');
// Allow selection of multiple results. NOTE - you must handle the selected IDs (comma separated list) in code
$field->setConfig('multiple', true);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.