本文整理汇总了PHP中kartik\select2\Select2类的典型用法代码示例。如果您正苦于以下问题:PHP Select2类的具体用法?PHP Select2怎么用?PHP Select2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Select2类的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: init
/**
*
*/
public function init()
{
if (empty($this->parentName)) {
throw new InvalidParamException('RelativeSelect2 $parentName must be set!');
}
if (empty($this->url)) {
throw new InvalidParamException('RelativeSelect2 $url must be set!');
}
if ($this->parentModel instanceof Model) {
$this->options['data']['select2-parent-name'] = Html::getInputName($this->parentModel, $this->parentName);
} else {
$this->options['data']['select2-parent-name'] = $this->hasModel() ? Html::getInputName($this->model, $this->parentName) : $this->parentName;
}
if (is_array($this->url)) {
$this->url = Url::to($this->url);
}
$this->options['data']['select2-url'] = $this->url;
if (!empty($this->model) && isset($this->model->{$this->attribute})) {
if (is_array($this->model->{$this->attribute})) {
$this->options['data']['select2-selected-items'] = implode(',', $this->model->{$this->attribute});
} else {
$this->options['data']['select2-selected-items'] = $this->model->{$this->attribute};
}
} else {
$this->options['data']['select2-selected-items'] = $this->value;
}
parent::init();
RelativeSelect2Asset::register($this->getView());
}
示例3: 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']);
}
示例4: init
public function init()
{
$this->setDefaultOptions();
if ($this->getSelect2Type() == 'ajax') {
$this->setAjaxOptions();
}
parent::init();
}
示例5: 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;
}
示例6: 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();
}']]);
}
示例7: selectField
function selectField($attribute, $data, $widgetOptions = [], $fieldOptions = [])
{
$defaultFieldOptions = ['options' => ['class' => 'form-group']];
$defaultInputOptions = ['class' => 'form-control select', 'placeholder' => $this->model->getAttributeLabel($attribute) . '...'];
$fieldOptions = array_replace_recursive($defaultFieldOptions, $fieldOptions);
$inputOptions = array_replace_recursive($defaultInputOptions, isset($widgetOptions['inputOptions']) ? $widgetOptions['inputOptions'] : []);
if ($this->viewMode || in_array($attribute, $this->disabledFields)) {
$fieldOptions['enableClientValidation'] = false;
$inputOptions['disabled'] = 'disabled';
}
$defaultWidgetOptions = ['data' => $data, 'options' => $inputOptions, 'pluginOptions' => ['allowClear' => true, 'minimumResultsForSearch' => 1]];
$widgetOptions = array_replace_recursive($defaultWidgetOptions, $widgetOptions);
return $this->form->field($this->model, $attribute, $fieldOptions)->widget(Select2::classname(), $widgetOptions);
}
示例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:
echo $form->field($model, 'id')->textInput(['disabled' => 'disabled', 'placeholder' => 'autonumber']);
?>
<?php
echo $form->field($model, 'number')->textInput(['maxlength' => true]);
?>
<?php
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
<?php
echo $form->field($model, 'city_id')->widget(DepDrop::classname(), ['data' => [], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]], 'pluginOptions' => ['initialize' => TRUE, 'placeholder' => 'Select or type city', 'depends' => ['rgndistrictform-province_id'], 'url' => Url::to(['/rgn-city/depdrop-options', 'selected' => $model->city_id]), 'loadingText' => 'Loading cities ...']]);
?>
<?php
echo $form->field($model, 'province_id')->widget(DepDrop::classname(), ['data' => [], 'type' => DepDrop::TYPE_SELECT2, 'select2Options' => ['pluginOptions' => ['multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]], 'pluginOptions' => ['initialize' => TRUE, 'placeholder' => 'Select or type province', 'depends' => ['rgndistrictform-country_id'], 'url' => Url::to(['/rgn-province/depdrop-options', 'selected' => $model->province_id]), 'loadingText' => 'Loading provinces ...']]);
?>
<?php
echo $form->field($model, 'country_id')->widget(Select2::classname(), ['data' => RgnCountry::asOption(), 'pluginOptions' => ['placeholder' => 'Select or type Country', 'multiple' => FALSE, 'allowClear' => TRUE, 'tags' => TRUE, 'maximumInputLength' => 255]]);
?>
</p>
<?php
$this->endBlock();
?>
<?php
echo Tabs::widget(['encodeLabels' => false, 'items' => [['label' => 'RgnDistrict', 'content' => $this->blocks['main'], 'active' => true]]]);
?>
<hr/>
<?php
echo $form->errorSummary($model);
?>
<?php
示例13:
<div class="row">
<div class="col-lg-6 col-xs-6">
<?php
echo $form->field($model, 'category_id')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите категорию ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
<?php
echo $form->field($model, 'producer_id')->widget(Select2::classname(), ['data' => ArrayHelper::map(Producer::find()->all(), 'id', 'name'), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите бренд ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
</div>
<div class="col-lg-6 col-xs-6">
<?php
echo $form->field($model, 'category_ids')->label('Прочие категории')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['multiple' => true, 'placeholder' => 'Доп. категории ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
</div>
</div>
<?php
echo $form->field($model, 'text')->widget(\yii\imperavi\Widget::className(), ['plugins' => ['fullscreen', 'fontcolor', 'video'], 'options' => ['minHeight' => 400, 'maxHeight' => 400, 'buttonSource' => true, 'imageUpload' => Url::toRoute(['tools/upload-imperavi'])]]);
?>
<?php
echo $form->field($model, 'short_text')->textInput(['maxlength' => true]);
?>
<?php
echo Gallery::widget(['model' => $model]);
?>
示例14:
$form = ActiveForm::begin(['layout' => 'horizontal']);
?>
<div>
<?php
echo $form->errorSummary($model);
?>
<?php
$this->beginBlock('main');
?>
<p>
<?php
/*= $form->field($model, 'client_id')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Client::find()->active()->all(), 'id', 'name'), ['prompt' => '']) */
?>
<?php
echo $form->field($model, 'client_id')->widget(\kartik\select2\Select2::className(), ['data' => \yii\helpers\ArrayHelper::map(\common\models\Client::find()->active()->all(), 'id', 'name'), 'options' => ['prompt' => '']]);
?>
<?php
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
<?php
echo $form->field($model, 'email')->input('email', ['maxlength' => true]);
?>
<?php
echo $form->field($model, 'phone')->input('tel', ['maxlength' => true, 'placeholder' => '(10 digits only)']);
?>
<?php
示例15:
foreach ($rces as $i => $rce) {
$ids[$i] = $rce->reserva_id;
}
$data = ArrayHelper::map(Reserva::find()->where(['not in', 'id', $ids])->all(), 'id', 'ReservaSelect');
?>
<?php
echo $form->field($model, "reserva_id")->widget(Select2::classname(), ['data' => $data, 'options' => ['placeholder' => 'Seleccionar Reserva...', 'id' => 'reservaId'], 'pluginOptions' => ['width' => '300px', 'disabled' => !$model->isNewRecord]]);
?>
<?php
$data = ArrayHelper::map(Profesional::find()->all(), 'id', 'Nombres');
?>
<?php
echo $form->field($model, "persona_id_realiza_examen")->widget(Select2::classname(), ['data' => $data, 'options' => ['placeholder' => 'Seleccionar Profesional que realiza el Examen...'], 'pluginOptions' => ['width' => '300px', 'disabled' => !$model->isNewRecord]]);
?>
<?php
foreach ($modelsExamenes as $i => $modelExamen) {
$script = <<<JS
// here you right all your javascript stuff
\$('#reservaId').change(function(){
var reservaId = \$(this).val();
\$.get('index.php?r=examen/get-datos-examen',{ reservaId : reservaId },function(data){
var data = \$.parseJSON(data);
\$('#rceexamenexamen-{$i}-monto_a_pagar').attr('value',data[{$i}].monto);
\$('#rceexamenexamen-{$i}-descripcion').attr('value',data[{$i}].descripcion);
\$('#rceexamenexamen-{$i}-observaciones').attr('value',data[{$i}].observaciones);
});