<?php /** * Partial to create or edit Group model */ use app\assets\Select2Asset; use app\assets\ImagePickerAsset; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\widgets\ActiveForm; Select2Asset::register($this); ImagePickerAsset::register($this); $app = \Yii::$app; $app->imageFilter->setThumbnailSettings(['mode' => 'inset', 'width' => 100, 'height' => 100]); $modelPictures = $model->isNewRecord ? [] : ArrayHelper::map($app->imageFilter->filterImages($model->pictures), 'name', 'url'); $availablePictures = ArrayHelper::map($app->imageFilter->protectedImages, 'name', 'url'); $availableParents = ArrayHelper::map($model->availableParents, 'id', 'name'); $availableProducts = ArrayHelper::map($model->availableProducts, 'id', 'name'); $picturesOptions = array_map(function ($var) { return ['data-img-src' => $var]; }, $modelPictures); $availablePicturesOptions = array_map(function ($var) { return ['data-img-src' => $var]; }, $availablePictures); $form = ActiveForm::begin(['id' => 'group-form', 'options' => ['data' => ['pjax' => 1]], 'action' => $model->isNewRecord ? ['/group/create'] : ['/group/update', 'id' => $model['id']]]); $addon_options = ['options' => ['class' => 'input-group'], 'labelOptions' => ['class' => 'input-group-addon'], 'errorOptions' => ['class' => 'input-group-addon error']]; echo $form->field($model, 'name', $addon_options)->textInput(); echo $form->field($model, 'parent', $addon_options)->dropDownList($availableParents, ['prompt' => '']); echo $form->field($model, 'description', $addon_options)->textarea(); echo $form->field($model, 'mainPicture')->dropDownList($modelPictures, ['class' => 'image-picker', 'options' => $picturesOptions]); echo $form->field($model, 'pictures')->dropDownList($availablePictures, ['class' => 'image-picker', 'multiple' => true, 'options' => $availablePicturesOptions]);
<?php use yii\bootstrap\ActiveForm; use yii\helpers\Html; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model app\models\Users */ /* @var $form yii\widgets\ActiveForm */ \app\assets\Select2Asset::register($this); ?> <br> <?php $form = ActiveForm::begin(['action' => Url::to(['translation/load']), 'options' => ['enctype' => 'multipart/form-data']]); echo $form->errorSummary($model); ?> <?php echo $form->field($model, 'file')->fileInput(['placeholder' => $model->getAttributeLabel('file')]); echo $form->field($model, 'isUpdate')->checkbox(); ?> <div class="hidden"> <?php echo $form->field($model, 'language')->hiddenInput(['style' => 'display:none']); ?> </div> <?php echo Html::submitButton(Yii::t('translation_load', ":upload_translation_file"), ['class' => 'btn btn-success']); ?>
/** * Register Select2 scripts. */ protected function registerClientScript() { $clientOptions = array_merge($this->clientOptions, $this->remoteClientOptions()); $clientOptions = Json::encode($clientOptions); $view = $this->getView(); $id = isset($this->options['id']) ? $this->options['id'] : $this->getId(); $view->registerJs("jQuery('#{$id}').select2({$clientOptions});"); if ($this->clientEvents) { $js = []; foreach ($this->clientEvents as $event => $callback) { if (!$callback instanceof JsExpression) { $callback = new JsExpression($callback); } $js[] = "jQuery('#{$id}').on('{$event}', {$callback});"; } if (!empty($js)) { $js = implode("\n", $js); $view->registerJs($js); } } $asset = Select2Asset::register($view); if ($this->language) { $asset->language = $this->language; } }