/** * @inheritdoc */ public function init() { if (!in_array($this->layout, ['default', 'horizontal', 'inline'])) { throw new InvalidConfigException('Invalid layout type: ' . $this->layout); } if ($this->layout !== 'default') { Html::addCssClass($this->options, 'form-' . $this->layout); } if (!isset($this->fieldConfig['class'])) { $this->fieldConfig['class'] = ActiveField::className(); } parent::init(); }
$this->title = Yii::t('back', 'add photos into gallery'); $this->params['breadcrumbs'][] = ['label' => Yii::t('back', 'Galleries'), 'url' => ['gallery/index']]; $this->params['breadcrumbs'][] = ['label' => $gallery->title . ' - ' . Yii::t('back', 'photos in gallery'), 'url' => ['gallery/photos', 'id' => $model->item_id]]; $this->params['breadcrumbs'][] = $this->title; FormAsset::register($this); ?> <div> <h1><?php echo Html::encode($this->title); ?> </h1> <?php $form = ActiveForm::begin(['fieldClass' => ActiveField::className()]); ?> <div class="form-group"> <?php echo Html::checkbox('selectAll', null, ['class' => 'selectAll']) . ' ' . Yii::t('back', 'select all images on this page'); ?> </div> <div class="row"> <div class="col-xs-12"> <?php echo ListView::widget(['dataProvider' => $dataProvider, 'itemView' => '_photo', 'viewParams' => compact('form'), 'layout' => "<div class=\"row\">{items}</div>\n{pager}"]); ?> </div> </div>
/** * @param \netis\crud\db\ActiveRecord $model * @param string $attribute * @param array $options * @param bool $multiple * * @return \yii\bootstrap\ActiveField * @throws InvalidConfigException */ public static function createActiveField($model, $attribute, $options = [], $multiple = false) { /** @var Formatter $formatter */ $formatter = Yii::$app->formatter; $stubForm = new \stdClass(); $stubForm->layout = 'default'; /** @var \yii\bootstrap\ActiveField $field */ $field = Yii::createObject(['class' => \yii\bootstrap\ActiveField::className(), 'model' => $model, 'attribute' => $attribute, 'form' => $stubForm]); $attributeName = Html::getAttributeName($attribute); $attributeFormat = $model->getAttributeFormat($attributeName); $format = is_array($attributeFormat) ? $attributeFormat[0] : $attributeFormat; $column = $model->getTableSchema()->getColumn($attributeName); switch ($format) { case 'boolean': if ($multiple) { $field->inline()->radioList(['0' => $formatter->booleanFormat[0], '1' => $formatter->booleanFormat[1], '' => Yii::t('app', 'Any')], $options); } else { $field->checkbox($options); } break; case 'shortLength': $value = Html::getAttributeValue($model, $attribute); if (!isset($options['value'])) { $options['value'] = $value === null ? null : $formatter->asMultiplied($value, 1000); } $field->textInput($options); $field->inputTemplate = '<div class="input-group">{input}<span class="input-group-addon">m</span></div>'; break; case 'shortWeight': $value = Html::getAttributeValue($model, $attribute); if (!isset($options['value'])) { $options['value'] = $value === null ? null : $formatter->asMultiplied($value, 1000); } $field->textInput($options); $field->inputTemplate = '<div class="input-group">{input}<span class="input-group-addon">kg</span></div>'; break; case 'multiplied': $value = Html::getAttributeValue($model, $attribute); if (!isset($options['value'])) { $options['value'] = $value === null ? null : $formatter->asMultiplied($value, $attributeFormat[1]); } $field->textInput($options); break; case 'integer': if (!isset($options['value'])) { $options['value'] = Html::getAttributeValue($model, $attribute); } $field->textInput($options); break; case 'time': if (!isset($options['value'])) { $options['value'] = Html::encode(Html::getAttributeValue($model, $attribute)); } $field->textInput($options); break; case 'datetime': case 'date': if (!isset($options['value'])) { $value = Html::getAttributeValue($model, $attribute); if (!$model->hasErrors($attribute) && $value !== null) { $value = $formatter->format($value, $format); } $options['value'] = $value; } if (!isset($options['class'])) { $options['class'] = 'form-control'; } $field->parts['{input}'] = array_merge(['class' => \omnilight\widgets\DatePicker::className(), 'model' => $model, 'attribute' => $attributeName, 'options' => $options], $format !== 'datetime' ? [] : ['class' => \kartik\datetime\DateTimePicker::className(), 'convertFormat' => true]); break; case 'enum': $items = $formatter->getEnums()->get($attributeFormat[1]); if ($multiple) { $options = array_merge(['class' => 'select2', 'placeholder' => self::getPrompt(), 'multiple' => 'multiple'], $options); $field->parts['{input}'] = ['class' => \maddoger\widgets\Select2::className(), 'model' => $model, 'attribute' => $attribute, 'items' => $items, 'clientOptions' => ['allowClear' => true, 'closeOnSelect' => true], 'options' => $options]; } else { if ($column !== null && $column->allowNull) { $options['prompt'] = self::getPrompt(); } $field->dropDownList($items, $options); } break; case 'flags': throw new InvalidConfigException('Flags format is not supported by ' . get_called_class()); case 'paragraphs': if (!isset($options['value'])) { $options['value'] = Html::encode(Html::getAttributeValue($model, $attribute)); } if ($multiple) { $field->textInput($options); } else { $field->textarea(array_merge(['cols' => '80', 'rows' => '10'], $options)); } break; case 'file': if (!isset($options['value'])) { $options['value'] = Html::getAttributeValue($model, $attribute); } $field->fileInput($options); break; default: case 'text': if (!isset($options['value'])) { $options['value'] = Html::getAttributeValue($model, $attribute); } if ($column && $column->type === 'string' && $column->size !== null) { $options['maxlength'] = $column->size; } $field->textInput($options); break; } return $field; }
use backend\assets\FormAsset; use common\models\WebRecord; use yii\bootstrap\ActiveField; use yii\helpers\Html; use yii\bootstrap\ActiveForm; /* @var $this yii\web\View */ /* @var $model common\models\WebRecord */ /* @var $form yii\bootstrap\ActiveForm */ FormAsset::register($this); ?> <div> <?php $form = ActiveForm::begin(['layout' => 'horizontal', 'fieldClass' => ActiveField::className(), 'fieldConfig' => Yii::$app->params['fieldConfig'], 'options' => ['id' => 'web-form']]); ?> <?php echo $form->field($model, 'title')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'weburl')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($model, 'theme')->dropDownList(Yii::$app->params['themeOptions']); ?> <?php
/** * @inheritdoc */ public function run() { $this->begin($this->config); if ($this->displayErrorSummary) { echo $this->errorSummary($this->model); } foreach ($this->fields as $field) { if (is_array($field)) { if (!method_exists(ActiveField::className(), $field[1])) { echo $this->field($this->model, $field[0], isset($field[2]) ? $field[2] : [])->widget($field[1], isset($field[3]) ? $field[3] : []); } else { if (!stripos($field[1], 'list')) { echo $this->field($this->model, $field[0], isset($field[2]) ? $field[2] : [])->{$field}[1](isset($field[3]) ? $field[3] : []); } else { echo $this->field($this->model, $field[0], isset($field[3]) ? $field[3] : [])->{$field}[1](isset($field[2]) ? $field[2] : [], isset($field[4]) ? $field[4] : []); } } } elseif (is_string($field)) { echo $this->field($this->model, $field)->textInput(); } else { throw new InvalidConfigException('Each field should be either a string or array.'); } } echo Html::beginTag('div', $this->buttonGroupOptions); foreach ($this->buttons as $btn) { echo $btn; } echo Html::endTag('div'); parent::run(); }
</div> </div> <?php if ($periodModel->existsActualPlans()) { ?> <div class="row"> <div class="col-xs-12"> <h2><?php echo Module::t('res', 'Usage overview'); ?> </h2> <?php $form = ActiveForm::begin(['layout' => 'inline', 'fieldClass' => ActiveField::className(), 'fieldConfig' => ['labelOptions' => ['class' => ''], 'enableError' => true]]); ?> <?php echo $form->field($periodModel, 'firstDate')->widget(DateControl::className(), ['type' => DateControl::FORMAT_DATE, 'language' => Yii::$app->language]); ?> <?php echo $form->field($periodModel, 'lastDate')->widget(DateControl::className(), ['type' => DateControl::FORMAT_DATE, 'language' => Yii::$app->language]); ?> <?php echo Html::submitButton(Module::t('res', 'OK'), ['class' => 'btn btn-default', 'style' => 'position: relative; top: -5px;']); ?> <?php