PHP code example of moonlandsoft / bootui-select2
1. Go to this page and download the library: Download moonlandsoft/bootui-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/ */
moonlandsoft / bootui-select2 example snippets
echo Select2::widget([
'name' => 'selection-name',
'value' => 'first',
'items' => ['first' => 'First Option', 'second' => 'Second Option', 'third' => 'Third Option'],
'options' => ['class' => 'form-control'],
'addon' => ['prepend' => 'Select']
]);
echo $form->field($model, 'attribute')->widget(Select2::className(), [
'items' => ['first' => 'First Option', 'second' => 'Second Option', 'third' => 'Third Option'],
'options' => ['class' => 'form-control'],
'addon' => ['prepend' => 'Select']
]);
use moonland\select2\Select2;
echo $form->field($model, 'attribute1')->widget(Select2::className(), [
'items' => ['first' => 'First Option', 'second' => 'Second Option', 'third' => 'Third Option'],
'size' => Select2::LARGE,
'addon' => [
'prepend' => [Html::a('btn1', '#', ['class' => 'btn btn-default']), true], // prepend in single button, format [String $content, Boolean $asButton]
'append' => [ // append in multiple button.
[bootui\Button::widget(['label' => 'btn 2']), true],
[bootui\Button::className(), ['label' => 'btn 3'], true], // format [$className, Array $config, Boolean $asButton]
],
],
]);
echo $form->field($model, 'attribute2')->widget(Select2::className(), [
'items' => ['data1' => 'First Data', 'data2' => 'Second Data', 'data3' => 'Third Data'],
'events' => [
'select2-opening' => 'function() { log("opening"); }',
'select2-open' => 'function() { log("open"); }',
'select2-close' => 'function() { log("close"); }',
],
'addon' => [
'prepend' => 'Select Data',
],
]);
echo Select2::widget([
//jquery inline function
'formatResult' => new JsExpression('function format(state) { if (!state.id) return state.text;return "" + state.text;}'),
//call existing function
'formatSelection' => new JsExpression('formatSelection()'),
//object
'data' => new JsExpression('[{id:0,text:"enhancement"},{id:1,text:"bug"},{id:2,text:"duplicate"},{id:3,text:"invalid"},{id:4,text:"wontfix"}]'),
]);
php composer.phar