PHP Class kartik\select2\Select2

See also: https://github.com/select2/select2
Since: 1.0
Author: Kartik Visweswaran ([email protected])
Inheritance: extends kartik\base\InputWidget
Show file Open project: kartik-v/yii2-widget-select2 Class Usage Examples

Public Properties

Property Type Description
$accesskey Implements open selector with accesskey
$addon addon to prepend or append to the Select2 widget - prepend: _array_|_string_, the prepend addon configuration. If set as a string will be rendered as is. If set as an array, the following properties can be set: - content: _string_, the prepend addon content. - asButton: _boolean, whether the addon is a button or button group. Defaults to false. - append: _array_|_string_, the append addon configuration. If set as a string will be rendered as is. If set as an array, the following properties can be set: - content: _string_, the append addon content. - asButton: _boolean, whether the addon is a button or button group. Defaults to false. - groupOptions: _array_, HTML options for the input group - contentBefore: _string_, content placed before addon - contentAfter: _string_, content placed after addon
$changeOnReset whether to trigger change for Select2 input on form reset so the Select2 value is rightly reset.
$data array the option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [[ArrayHelper::map()]].
$hideSearch whether to hide the search control and render it as a simple select.
$initValueText
$language the locale ID (e.g. 'fr', 'de') for the language to be used by the Select2 Widget. If this property not set, then the current application language will be used.
$maintainOrder whether to maintain the order of tag / option selected for a multiple select
$options the HTML attributes for the input tag. The following options are important: - multiple: _boolean_, whether multiple or single item should be selected. Defaults to false. - placeholder: _string_, placeholder for the select item.
$pluginName the name of the jQuery plugin
$showToggleAll whether to show the toggle all button for selection all options in a multiple select.
$size Size of the Select2 input, must be one of the [[Select2::LARGE]], [[Select2::MEDIUM]] or [[Select2::SMALL]].
$theme the theme name to be used for styling the Select2.
$toggleAllSettings the toggle all button settings for selecting/unselecting all the options. This is applicable only for multiple select. The following array key properties can be set: - selectLabel: _string_, the markup to be shown to select all records. Defaults to: Select all. - unselectLabel: _string_, the markup to be shown to unselect all records. Defaults to: Unselect all. - selectOptions: _array_, the HTML attributes for the container wrapping the select label. Defaults to []. - unselectOptions: _array_, the HTML attributes for the container wrapping the unselect label. Defaults to []. - options: _array_, the HTML attributes for the toggle button container. Defaults to: ['class' => 's2-togall-button'].

Protected Properties

Property Type Description
$_inbuiltThemes list of inbuilt themes
$_msgCat
$_s2OptionsVar the variable that will store additional options for Select2 to add enhanced features after the plugin is loaded and initialized. This variable name will be stored as a data attribute data-s2-options within the base select input options.

Public Methods

Method Description
registerAssetBundle ( ) Registers the asset bundle and locale
registerAssets ( ) Registers the client assets for Select2 widget.
renderWidget ( ) Initializes and renders the widget
run ( )

Protected Methods

Method Description
embedAddon ( string $input ) : string Embeds the input group addon
initPlaceholder ( ) Initializes the placeholder for Select2
parseBool ( mixed $var ) : yii\web\JsExpression Parses the variable for boolean value and returns a right JS expression
renderInput ( ) Renders the source Input for the Select2 plugin. Graceful fallback to a normal HTML select dropdown or text input - in case JQuery is not supported by the browser
renderToggleAll ( ) Initializes and render the toggle all button

Method Details

embedAddon() protected method

Embeds the input group addon
protected embedAddon ( string $input ) : string
$input string
return string

initPlaceholder() protected method

Initializes the placeholder for Select2
protected initPlaceholder ( )

parseBool() protected static method

Parses the variable for boolean value and returns a right JS expression
protected static parseBool ( mixed $var ) : yii\web\JsExpression
$var mixed the variable value to parse
return yii\web\JsExpression

registerAssetBundle() public method

Registers the asset bundle and locale
public registerAssetBundle ( )

registerAssets() public method

Registers the client assets for Select2 widget.
public registerAssets ( )

renderInput() protected method

Renders the source Input for the Select2 plugin. Graceful fallback to a normal HTML select dropdown or text input - in case JQuery is not supported by the browser
protected renderInput ( )

renderToggleAll() protected method

Initializes and render the toggle all button
protected renderToggleAll ( )

renderWidget() public method

Initializes and renders the widget
public renderWidget ( )

run() public method

public run ( )

Property Details

$_inbuiltThemes protected static property

list of inbuilt themes
protected static $_inbuiltThemes

$_msgCat protected property

protected $_msgCat

$_s2OptionsVar protected property

the variable that will store additional options for Select2 to add enhanced features after the plugin is loaded and initialized. This variable name will be stored as a data attribute data-s2-options within the base select input options.
protected $_s2OptionsVar

$accesskey public property

Implements open selector with accesskey
public $accesskey

$addon public property

addon to prepend or append to the Select2 widget - prepend: _array_|_string_, the prepend addon configuration. If set as a string will be rendered as is. If set as an array, the following properties can be set: - content: _string_, the prepend addon content. - asButton: _boolean, whether the addon is a button or button group. Defaults to false. - append: _array_|_string_, the append addon configuration. If set as a string will be rendered as is. If set as an array, the following properties can be set: - content: _string_, the append addon content. - asButton: _boolean, whether the addon is a button or button group. Defaults to false. - groupOptions: _array_, HTML options for the input group - contentBefore: _string_, content placed before addon - contentAfter: _string_, content placed after addon
public $addon

$changeOnReset public property

whether to trigger change for Select2 input on form reset so the Select2 value is rightly reset.
public $changeOnReset

$data public property

the option data items. The array keys are option values, and the array values are the corresponding option labels. The array can also be nested (i.e. some array values are arrays too). For each sub-array, an option group will be generated whose label is the key associated with the sub-array. If you have a list of data models, you may convert them into the format described above using [[ArrayHelper::map()]].
public array $data
return array

$hideSearch public property

whether to hide the search control and render it as a simple select.
public $hideSearch

$initValueText public property

public $initValueText

$language public property

the locale ID (e.g. 'fr', 'de') for the language to be used by the Select2 Widget. If this property not set, then the current application language will be used.
public $language

$maintainOrder public property

whether to maintain the order of tag / option selected for a multiple select
public $maintainOrder

$options public property

the HTML attributes for the input tag. The following options are important: - multiple: _boolean_, whether multiple or single item should be selected. Defaults to false. - placeholder: _string_, placeholder for the select item.
public $options

$pluginName public property

the name of the jQuery plugin
public $pluginName

$showToggleAll public property

whether to show the toggle all button for selection all options in a multiple select.
public $showToggleAll

$size public property

Size of the Select2 input, must be one of the [[Select2::LARGE]], [[Select2::MEDIUM]] or [[Select2::SMALL]].
public $size

$theme public property

the theme name to be used for styling the Select2.
public $theme

$toggleAllSettings public property

the toggle all button settings for selecting/unselecting all the options. This is applicable only for multiple select. The following array key properties can be set: - selectLabel: _string_, the markup to be shown to select all records. Defaults to: Select all. - unselectLabel: _string_, the markup to be shown to unselect all records. Defaults to: Unselect all. - selectOptions: _array_, the HTML attributes for the container wrapping the select label. Defaults to []. - unselectOptions: _array_, the HTML attributes for the container wrapping the unselect label. Defaults to []. - options: _array_, the HTML attributes for the toggle button container. Defaults to: ['class' => 's2-togall-button'].
public $toggleAllSettings