Основной блок
= $form->field($product, 'image', [ 'options' => [ 'class' => 'form-group filed-upload-imgs' ] ])
->widget(
ImageInput::class,
[
'showPreview' => true,
]
); ?>
= $form->field($product, 'brand_id')
->widget(
Select2::class,
[
'options' => [
'placeholder' => \Yii::t('app', 'Выберите бренд'),
],
'data' => $brands,
'pluginOptions' => [
'allowClear' => true,
],
]
) ?>
= $form->field($product, 'categoryIds')
->dropDownList(
$categoriesData,
[
'options' => $categoriesOptions,
'multiple' => true,
]
) ?>
= $form->field($product, "optionIds")
->widget(
Select2::class,
[
'options' => [
'placeholder' => \Yii::t('app', 'Выберите фильтры'),
'multiple' => true,
],
'data' => $options,
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 1,
'language' => [
'errorLoading' => new \yii\web\JsExpression(
"function () { return 'Waiting for results...'; }"
),
],
'ajax' => [
'url' => \yii\helpers\Url::to([ '/filter/group/find-options' ]),
'dataType' => 'json',
'data' => new \yii\web\JsExpression(
'function(params) {
return {
q:params.term
};
}'
),
],
'escapeMarkup' => new \yii\web\JsExpression(
'function (markup) {
return markup;
}'
),
'templateResult' => new \yii\web\JsExpression(
'function (brand) {
return brand.text;
}'
),
'templateSelection' => new \yii\web\JsExpression(
'function (brand) {
return brand.text;
}'
),
],
]
) ?>
context->module->productCommonFields as $field) {
switch ($field[ 'type' ]) {
case Form::STRING :
echo $form->field($product, $field[ 'name' ])
->textInput();
break;
case Form::TEXTAREA :
echo $form->field($product, $field[ 'name' ])
->textarea();
break;
case Form::WYSIWYG :
$form->field($product, $field[ 'name' ])
->widget(
\mihaildev\ckeditor\CKEditor::class,
[
'editorOptions' => \yii\helpers\ArrayHelper::merge(
\mihaildev\elfinder\ElFinder::ckeditorOptions(
'elfinder',
[
'language' => 'ru',
]
),
[
'preset' => 'standart',
'removeButtons' => 'SelectAll,Find,Replace,Flash,Smiley,PageBreak,ShowBlocks,Save,NewPage,Print,Templates,ImageButton,Select,Button,Textarea,Radio,Checkbox,Form,Subscript,Superscript,CopyFormatting,RemoveFormat,CreateDiv,Language,HiddenField,About,TextField,Font,FontSize',
'allowedContent' => true,
]
),
]
);
break;
case Form::IMAGE:
echo $form->field(
$product,
$field[ 'name' ],
[ 'options' => [ 'class' => 'form-group filed-upload-imgs' ] ]
)
->widget(
ImageInput::class,
[
'showPreview' => true,
]
);
break;
case Form::BOOL:
echo $form->field(
$product,
$field[ 'name' ],
[
'template' => "
{label}
\n{input}\n{error}",
]
)
->checkbox(
[
'class' => 'switchery',
],
false
);
break;
case Form::NUMBER:
echo $form->field(
$product,
$field[ 'name' ],
[
'template' => '{label}
{input}
{error}{hint}',
'options' => [ 'class' => 'form-group filed-sort' ],
]
);
break;
case Form::RELATION:
$isMultiple = $field[ 'multiple' ] ?? false;
$relationInfo = new RelationInfo($product::className(), $field[ 'relationName' ]);
echo $form->field($product, $field[ 'name' ])
->widget(
Select2::classname(),
[
'data' => $relationInfo->getAllFields($field[ 'relationAttribute' ]),
'options' => [
'placeholder' => \Yii::t('core', 'Select ...'),
'multiple' => $isMultiple,
],
'pluginOptions' => [
'allowClear' => true,
],
]
);
break;
case Form::SELECT:
$isMultiple = $field[ 'multiple' ] ?? false;
echo $form->field($product, $field[ 'name' ])
->widget(
Select2::classname(),
[
'data' => $field[ 'data' ],
'options' => [
'placeholder' => \Yii::t('core', 'Select ...'),
'multiple' => $isMultiple,
],
'pluginOptions' => [
'allowClear' => true,
],
]
);
break;
case Form::DATE:
DateRangePicker::register($this);
$mindate = date("d-m-Y H:i");
$value = $this->model->{$field[ 'name' ]};
$js = <<< JS
var dateRangeInputFrom = $('#date_field');
var dateFormat = '{$product->clientDateFormat}';
dateRangeInputFrom.daterangepicker({
singleDatePicker: true,
autoUpdateInput: true,
showDropdowns: true,
minDate: '{$mindate}',
timePicker: true,
timePicker24Hour: true,
locale: {
cancelLabel: 'Clear',
format: dateFormat
}
}, function(){
});
dateRangeInputFrom.on('cancel.daterangepicker', function() {
//do something, like clearing an input
dateRangeInputFrom.val('');
});
if ("{$value}" == ""){
dateRangeInputFrom.val('');
}
JS;
$this->registerJs($js, \yii\web\View::POS_READY);
echo $form->field(
$product,
$field[ 'name' ],
[ 'options' => [ 'class' => 'form-group date-search' ] ]
)
->textInput([ 'id' => "date_field" ]);
break;
case Form::WIDGET:
echo $form->field($product, $field[ 'name' ])
->widget($field[ 'className' ], $field[ 'options' ] ?? []);
break;
default:
throw new InvalidConfigException(
\Yii::t(
'core',
'Unavailable or unknown type: {type}',
[
'type' => $field[ 'type' ],
]
)
);
}
} ?>