Source of file Select2Field.php
Size: 1,479 Bytes - Last Modified: 2021-12-23T10:34:14+00:00
/var/www/docs.ssmods.com/process/src/code/Select2Field.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 | <?php namespace Sheadawson\Select2; use SilverStripe\Forms\DropdownField; use SilverStripe\View\Requirements; /** * Select2Field Definition * * @package Select2 * @author Shea Dawson <shea@silverstripe.com.au> */ class Select2Field extends DropdownField { /** * @var int The number of items that need to appear in the dropdown * in order to trigger a search bar */ public static $default_search_threshold = 12; /** * Sets the search threshold for this dropdown * * @param int $num The number of items */ public function setSearchThreshold($num) { return $this->setAttribute('data-search-threshold', $num); } public function Field($properties = array()) { Requirements::javascript('silverstripe/admin: thirdparty/jquery/jquery.js'); Requirements::javascript('silverstripe/admin: thirdparty/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript('sheadawson/silverstripe-select2: select2/select2.js'); Requirements::javascript('sheadawson/silverstripe-select2: javascript/ajaxselect2.init.js'); Requirements::css('sheadawson/silverstripe-select2: select2/select2.css'); $this->addExtraClass('select2')->addExtraClass('no-chzn'); if (!$this->getAttribute('data-search-threshold')) { $this->setSearchThreshold(self::$default_search_threshold); } return parent::Field($properties); } } |