本文整理汇总了PHP中kartik\select2\Select2::widget方法的典型用法代码示例。如果您正苦于以下问题:PHP Select2::widget方法的具体用法?PHP Select2::widget怎么用?PHP Select2::widget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kartik\select2\Select2
的用法示例。
在下文中一共展示了Select2::widget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$out = '';
$countryDropdown = Select2::widget(['name' => 'country', 'value' => '', 'data' => Country::dropdown(), 'options' => ['label' => 'yaya', 'placeholder' => 'Select Country ...', 'id' => 'country-selection']]);
$locationDropdown = $this->form->field($this->model, 'location_id')->label(false)->widget(DepDrop::classname(), ['type' => DepDrop::TYPE_SELECT2, 'options' => ['id' => 'location-selection'], 'select2Options' => ['pluginOptions' => ['allowClear' => TRUE]], 'pluginOptions' => ['depends' => ['country-selection'], 'placeholder' => 'Select Location', 'url' => Url::to(['/location/admin/load'])]]);
$this->_printField($countryDropdown, $out);
$this->_printField($locationDropdown, $out);
return $out;
}
示例2:
use kartik\select2\Select2;
use app\models\Streets;
/* @var $this yii\web\View */
/* @var $model app\models\Peoples */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="peoples-form">
<?php
$form = ActiveForm::begin();
?>
<?php
echo Html::label("Вулиця");
echo Select2::widget(['model' => $model, 'attribute' => 'streetId', 'language' => 'uk', 'data' => ArrayHelper::map(Streets::find()->all(), 'streetId', 'streetName')]);
?>
<?php
echo $form->field($model, 'yearVal')->textInput()->label('Кількість років');
?>
<div class="form-group">
<?php
echo Html::submitButton($model->isNewRecord ? 'Пошук' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
</div>
<?php
ActiveForm::end();
?>
示例3:
echo $form->field($model, 'phone');
echo $form->field($model, 'country');
echo $form->field($model, 'government');
echo $form->field($model, 'city');
echo $form->field($model, 'district');
echo $form->field($model, 'website');
echo $form->field($model, 'email');
?>
<?php
//echo $form->field($model, 'products[]')->dropDownList($model->getServices(),
//
// ['class' => 'form-control', 'multiple' => true]);
// Multiple select without model
echo "Products";
echo Select2::widget(['name' => 'products', 'value' => $selectedData, 'data' => $model->getServices(), 'options' => ['multiple' => true, 'placeholder' => 'Select Products ...']]);
?>
<?php
if ($settings['itemThumb']) {
?>
<?php
if ($model->image) {
?>
<img src="<?php
echo Image::thumb($model->image, 240);
?>
">
<a href="<?php
echo Url::to(['/admin/' . $module . '/items/clear-image', 'id' => $model->primaryKey]);
示例4: field
private static function field($key, $value, $sModel, $model)
{
if (strpos($sModel, "listT(") === 0) {
$modelName = str_replace("listT(", "", $sModel);
$modelName = str_replace(")", "", $modelName);
$type = substr($modelName, strpos($modelName, '[') + 1, strpos($modelName, '[') - strpos($modelName, ']') + 1);
//echo $type;
//exit;
$modelName = str_replace("[" . $type . "]", "", $modelName);
$temp = ArrayHelper::map($modelName::findAllByType($type), 'id', 'name');
$temp[''] = Yii::t('app', 'None');
//$label = Yii::t('app', $sModel->id) ;
$field = Html::dropDownList($model . '[' . $key . '][value]', $value, $temp) . "<br/>";
} elseif (strpos($sModel, "list(") === 0) {
$modelName = str_replace("list(", "", $sModel);
$modelName = str_replace(")", "", $modelName);
$temp = ArrayHelper::map($modelName::find()->All(), 'id', 'name');
$temp[''] = Yii::t('app', 'None');
//$label = Yii::t('app', $sModel->id) ;
$field = \kartik\select2\Select2::widget(["name" => $model . '[' . $key . '][value]', "data" => $temp, "value" => $value]);
} elseif (strpos($sModel, "select(") === 0) {
$list = str_replace("select(", "", $sModel);
//echo str_replace(")", "", $list);
//exit;
$list = Json::decode(str_replace(")", "", $list));
foreach ($list as &$item) {
//print $item;
$item = Yii::t('app', $item);
}
//$temp = Html::listData(\yii\helpers\Json::decode($list), 'id', 'name');
$temp[''] = Yii::t('app', 'None');
//$label = Yii::t('app', $sModel->id);
$field = \kartik\select2\Select2::widget(["name" => $model . '[' . $key . '][value]', "data" => $list, "value" => $value]);
} elseif ($sModel == 'file') {
$rKey = str_replace(".", "", $key);
//$label = Yii::t('app', $sModel->id) ;
$field = "<div class='row'><div class='btn-group '>" . Html::fileInput($model . '[' . $key . '][value]', $value, ['style' => 'display:none;', 'id' => $model . "_" . $rKey . "_input", "accept" => "image/gif,image/jpeg"]) . Html::hiddenInput($model . '[' . $key . '][value]', $value) . Html::buttonInput(Yii::t('app', 'Chose'), ['id' => $model . "_" . $rKey . "_upload"]) . Html::buttonInput(Yii::t('app', 'Delete'), ['id' => $model . "_" . $rKey . "_remove"]) . "</div></div>";
$idf = $model . "_" . $rKey . "_input";
$script = "\n \$(document).on('click','#{$model}_{$rKey}_upload', function () {\n \$('#{$idf}').click();\n });\n \$(document).on('click','#{$model}_{$rKey}_remove', function () {\n //del();\n });\n \n ";
Yii::$app->controller->view->registerJs($script, \yii\web\View::POS_READY);
} elseif ($sModel == 'boolean') {
//$label = Yii::t('app', $sModel->id);
$field = Html::hiddenInput($model . '[' . $key . '][value]', false) . Html::checkbox($model . '[' . $key . '][value]', $value == 'true' ? true : false, ['class' => 'form-control']);
} elseif ($sModel == 'date') {
//$label = Yii::t('app', $sModel->id);
$name = str_replace("[", "_", str_replace("]", "_", $model));
$id = $name . "-" . $key;
$rname = $model . "[" . $key . "][value]";
$timezone = Yii::$app->timezone;
$base = yii\helpers\BaseUrl::base();
$field = <<<java
<div class="input-group date">
<span class="input-group-addon kv-date-calendar" title="Select date">
<i class="glyphicon glyphicon-calendar"></i>
</span>
<input type="text" id="{$id}-disp" class="form-control" name="{$rname}-w0" value="{$value}" data-krajee-datecontrol="datecontrol_b5142286" data-datepicker-type="2" data-krajee-kvdatepicker="kvDatepicker_158f0063"></div>
<input type="hidden" id="{$id}" name="{$rname}">
<script>
var kvDatepicker_158f0063 = {"autoclose":true,"format":"dd/mm/yyyy"};
var datecontrol_37eef6f1 = {"idSave":"{$id}","url":"{$base}/datecontrol/parse/convert","type":"date","saveFormat":"Y-m-d","dispFormat":"d/m/Y","asyncRequest":true};
jQuery('#{$id}-disp').datecontrol(datecontrol_37eef6f1);
jQuery('#{$id}-disp').parent().kvDatepicker(kvDatepicker_158f0063);
</script>
java;
//$field.="<script>jQuery('#{$name}{$key}_value').datepicker();</script>";
} else {
//$label = Yii::t('app', $sModel->id);
$field = Html::textInput($model . '[' . $key . '][value]', $value, ['class' => 'form-control']);
}
return $field;
}
示例5: renderDropDownList
private function renderDropDownList($data, $value = null)
{
if (!count($data)) {
return;
}
return Select2::widget(['id' => md5(Html::getInputId($this->model, $this->attribute) . mt_rand(0, 999999999) . mt_rand(0, 999999999)), 'name' => '', 'value' => $value, 'data' => array_merge([0 => '...'], $data), 'language' => 'ru']);
}
示例6: run
public function run()
{
$variantsList = $this->field->variants;
$variantsList = ArrayHelper::map($variantsList, 'id', 'value');
$variantsList[0] = '-';
ksort($variantsList);
$checked = $this->model->getFieldVariantId($this->field->slug);
$select = Select2::widget(['name' => 'choice-field-value', 'value' => $checked, 'data' => $variantsList, 'language' => 'ru', 'options' => ['placeholder' => 'Выберите значение ...'], 'pluginOptions' => ['allowClear' => true]]);
$variants = Html::tag('div', $select, $this->options);
return $variants;
}
示例7: run
/** Render widget */
public function run()
{
$m = new $this->model_name();
$data = $m->allAsArray;
// Without model and implementing a multiple select
if ($this->title != '') {
echo '<label class="control-label">' . $this->title . '</label>';
}
echo \kartik\select2\Select2::widget(['name' => $this->behavior->post_name, 'data' => $data, 'value' => $this->model->relatedIdsArray, 'options' => ['placeholder' => $this->placeholder, 'multiple' => true, 'sorter' => 'function(data) {
return data.sort();
}']]);
}
示例8: init
/**
* @inherit doc
* @throw InvalidConfigException
*/
public function init()
{
if (empty($this->pluginOptions['url'])) {
throw new InvalidConfigException("The 'pluginOptions[\"url\"]' property has not been set.");
}
if (empty($this->pluginOptions['depends']) || !is_array($this->pluginOptions['depends'])) {
throw new InvalidConfigException("The 'pluginOptions[\"depends\"]' property must be set and must be an array of dependent dropdown element ID.");
}
if (empty($this->options['class'])) {
$this->options['class'] = 'form-control';
}
if ($this->type === self::TYPE_SELECT2) {
Config::checkDependency('select2\\Select2', 'yii2-widget-select2', 'for dependent dropdown for TYPE_SELECT2');
}
parent::init();
if ($this->type !== self::TYPE_SELECT2 && !empty($this->options['placeholder'])) {
$this->data = ['' => $this->options['placeholder']] + $this->data;
}
if ($this->type === self::TYPE_SELECT2 && (!empty($this->options['placeholder']) || !empty($this->select2Options['options']['placeholder']))) {
$this->pluginOptions['placeholder'] = '';
} elseif ($this->type === self::TYPE_SELECT2 && !empty($this->pluginOptions['placeholder']) && $this->pluginOptions['placeholder'] !== false) {
$this->options['placeholder'] = $this->pluginOptions['placeholder'];
$this->pluginOptions['placeholder'] = '';
}
$this->_view = $this->getView();
$this->registerAssets();
if ($this->type === self::TYPE_SELECT2) {
if (empty($this->data)) {
$this->data = ['' => ''];
}
if ($this->hasModel()) {
$settings = ArrayHelper::merge($this->select2Options, ['model' => $this->model, 'attribute' => $this->attribute, 'data' => $this->data, 'options' => $this->options]);
} else {
$settings = ArrayHelper::merge($this->select2Options, ['name' => $this->name, 'value' => $this->value, 'data' => $this->data, 'options' => $this->options]);
}
echo Select2::widget($settings);
$id = 'jQuery("#' . $this->options['id'] . '")';
$text = ArrayHelper::getValue($this->pluginOptions, 'loadingText', 'Loading ...');
$this->_view->registerJs("{$id}.on('depdrop.beforeChange',function(e,i,v){{$id}.select2('data',{text: '{$text}'});});");
$this->_view->registerJs("{$id}.on('depdrop.change',function(e,i,v,c){{$id}.select2('val',{$id}.val());});");
} else {
echo $this->getInput(!empty($this->typename) ? $this->typename : 'dropdownList', true);
}
}
示例9: run
public function run()
{
$variantsList = $this->filter->variants;
$variantsList = ArrayHelper::map($variantsList, 'id', 'value');
$variantsList[0] = '-';
ksort($variantsList);
$checked = false;
foreach ($variantsList as $variantId => $value) {
if ($this->model->checkedId($variantId)) {
$checked = $variantId;
break;
}
}
$select = Select2::widget(['name' => 'choise-option', 'value' => $checked, 'data' => $variantsList, 'language' => 'ru', 'options' => ['placeholder' => 'Выберите значение ...'], 'pluginOptions' => ['allowClear' => true]]);
$variants = Html::tag('div', $select, $this->options);
$new = [];
$new[] = Html::input('text', 'variant_value', '', ['placeholder' => 'Новый вариант', 'data-filter-id' => $this->filter->id, 'data-create-action' => Url::toRoute(['/filter/filter-variant/create']), 'class' => ' form-control']);
$new[] = Html::button(Html::tag('i', '', ['class' => 'glyphicon glyphicon-plus']), ['class' => 'btn btn-success']);
$variants .= Html::tag('div', implode('', $new), ['class' => 'new-variant']);
return $variants;
}
示例10: registerAssets
/**
* Registers the needed assets
*/
public function registerAssets()
{
$view = $this->getView();
DepDropAsset::register($view);
DepDropExtAsset::register($view);
$this->registerPlugin('depdrop');
if ($this->type === self::TYPE_SELECT2) {
$loading = ArrayHelper::getValue($this->pluginOptions, 'loadingText', 'Loading ...');
$this->select2Options['data'] = $this->data;
$this->select2Options['options'] = $this->options;
if ($this->hasModel()) {
$settings = ArrayHelper::merge($this->select2Options, ['model' => $this->model, 'attribute' => $this->attribute]);
} else {
$settings = ArrayHelper::merge($this->select2Options, ['name' => $this->name, 'value' => $this->value]);
}
echo Select2::widget($settings);
$id = $this->options['id'];
$view->registerJs("initDepdropS2('{$id}','{$loading}');");
} else {
echo $this->getInput('dropdownList', true);
}
}
示例11: widgetSendMessageModal
/**
* @param $view View
* @return string
* @throws \Exception
*/
public static function widgetSendMessageModal(&$view)
{
$view->registerJs("messageurl = '" . Url::to(['/users/send-message'], true) . "';");
ob_start();
Modal::begin(['header' => '<h3>' . Yii::t('app', 'Send Message') . '</h3>', 'id' => 'messagemodal', 'size' => 'modal-md', 'closeButton' => ['label' => '', 'class' => 'close glyphicon glyphicon-remove'], 'options' => ['tabindex' => false], 'footer' => '<button type="button" class="btn btn-default pull-right" data-dismiss="modal">' . Yii::t('app', 'Cancel') . '</button>' . '<button type="button" class="btn btn-primary pull-left" id="sendBtn">' . Yii::t('app', 'Send') . '</button>']);
$url = \yii\helpers\Url::to(['/users/search']);
echo Select2::widget(['options' => ['placeholder' => 'To:'], 'model' => new \app\models\User(), 'theme' => Select2::THEME_KRAJEE, 'name' => 'receiver_id', 'pluginOptions' => ['allowClear' => true, 'minimumInputLength' => 3, 'ajax' => ['url' => $url, 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }')], 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), 'templateResult' => new JsExpression('function(city) { return city.text; }'), 'templateSelection' => new JsExpression('function (city) { return city.text; }')]]);
$Message = Yii::t('app', 'Message');
$placeholder = Yii::t('app', 'Enter you message..');
echo <<<HTML
<div style="margin:20px 0 25px 0;">
<div class="form-group">
<label for="comment">{$Message} :</label>
<textarea placeholder="{$placeholder}" class="form-control" rows="5" id="message" style="max-width:100%;"></textarea>
</div>
</div>
HTML;
Modal::end();
return ob_get_clean();
}
示例12:
use app\modules\plan_prospekt\Asset;
/**
* @var $this View
* @var $actionSubview string
* @var $actionParams array
* @var $gridParams array
*/
ActiveFormAsset::register($this);
TouchSpinAsset::register($this);
DatePickerAsset::register($this);
GridViewAsset::register($this);
Asset::register($this);
echo Html::beginTag('div', ['class' => 'planprospekt planprospekt-editor']);
echo Html::tag('h3', 'План проспект ' . Yii::$app->request->get('year'));
// workaround for kratik-select2 pjax loading bug
echo Html::tag('div', Select2::widget(['name' => 'stub']), ['class' => 'hidden']);
Modal::begin(['id' => 'modal-action', 'header' => '<h4></h4>']);
$this->registerJs('mybriop.planProspektEditor.modalDynamicOptionsInit("#modal-action");');
Pjax::begin(['id' => 'pjax-action', 'timeout' => 3500]);
if (isset($actionSubview) && isset($actionParams)) {
$indexUrl = $actionParams['indexUrl'];
$modalMethod = $actionParams['model'] !== null ? "show" : "hide";
$this->registerJs('mybriop.planProspektEditor.modalHiddenHandlerInit("#modal-action", "#pjax-grid", "' . $indexUrl . '");');
$this->registerJs('$("#modal-action").modal("' . $modalMethod . '");');
echo $this->render($actionSubview, $actionParams);
}
Pjax::end();
Modal::end();
Pjax::begin(['id' => 'pjax-grid', 'timeout' => 3500]);
if (isset($gridParams)) {
$this->registerJs('mybriop.planProspektEditor.gridActionButtonsInit(".btn-action", "#pjax-action");');
示例13:
</div>
<div class="col-lg-6">
</div>
</div>
<div class="row">
<div class="col-lg-6">
<?php
echo '<label class="control-label">' . Yii::t('user', 'Обладает допусками') . '</label>';
?>
<?php
echo Select2::widget(['name' => 'AuthItem[children_array]', 'value' => array_keys($model->children_array), 'data' => AuthItem::getAll(), 'options' => ['multiple' => true], 'pluginOptions' => ['tags' => true]]);
?>
</div>
<div class="col-lg-6">
<?php
echo '<label class="control-label">' . Yii::t('user', 'Обладают пользователи') . '</label>';
?>
<?php
echo Select2::widget(['name' => 'AuthItem[user_array]', 'value' => array_keys($model->user_array), 'data' => User::getAll(), 'options' => ['multiple' => true], 'pluginOptions' => ['tags' => true]]);
?>
</div>
</div>
<?php
ActiveForm::end();
?>
</div>
示例14:
*/
use frontend\models\Watches;
use kartik\select2\Select2;
use yii\helpers\ArrayHelper;
?>
<td><?php
$i = $count + 1;
echo $i;
?>
</td>
<td>
<?php
echo Select2::widget(['model' => $model, 'attribute' => 'watches_id[' . $count . ']', 'data' => Arrayhelper::map(Watches::find()->all(), 'id', 'modelno'), 'options' => ['placeholder' => '', 'onchange' => '
$.post("/index.php/bills/bcontent?id=' . '"+$(this).val(),function(data){
$("#bills-description-' . $count . '").val(data["brand"]);
$("#bills-price-' . $count . '").val(data["price"]);
},"json");
'], 'pluginOptions' => ['allowClear' => true]]);
?>
</td>
<td>
<div class="form-group field-bills-description-<?php
echo $count;
?>
">
<input type="text" id="bills-description-<?php
echo $count;
?>
" class="form-control" name="Bills[description][<?php
echo $count;
示例15: explode
$arrayOptions = explode(',', $child->store_range);
foreach ($arrayOptions as $option) {
$options[$option] = Module::t('setting', $option);
}
$str .= Html::dropDownList("Setting[{$child->code}]", $child->value, $options, ["class" => "form-control"]);
} elseif ($child->type == 'multiselect') {
$options = [];
$arrayOptions = explode(',', $child->store_range);
foreach ($arrayOptions as $option) {
$options[$option] = Module::t('setting', $option);
}
// $str .= Html::listBox("Setting[$child->code]", $child->value, $options, [
// "class" => "form-control",
// "multiple" => "multiple"
// ]);
$str .= \kartik\select2\Select2::widget(['name' => "Setting[{$child->code}]", 'value' => $child->value, 'options' => ['multiple' => true, 'placeholder' => \Yii::t('common', 'Select default access rights for new users')], 'pluginOptions' => ['tags' => array_keys($options), 'createSearchChoice' => new \yii\web\JsExpression('function() { return null; }')]]);
// echo Select2::widget([
// 'name' => 'color_1',
// 'options' => ['placeholder' => 'Select a color ...'],
// 'pluginOptions' => [
// 'tags' => ["red", "green", "blue", "orange", "white", "black", "purple", "cyan", "teal"],
// 'maximumInputLength' => 10
// ],
// ]);
} elseif ($child->type == 'redactor') {
$options = [];
$arrayOptions = explode('|', $child->store_range);
foreach ($arrayOptions as $option) {
$options[$option] = $option;
}
\itzen\setting\RedactorPlugins::register($this);