Yii2 Fileinput allow multiple screenshot insert - yii2

I have a Fileinput field and I want to insert there screenshots one by one, using print screen, but Fileinput remove previous file. What can I do ?
use kartik\widgets\FileInput
echo '<label class="control-label">Add Attachments</label>';
echo FileInput::widget([
'model' => $model,
'attribute' => 'attachment_1[]',
'options' => ['multiple' => true]
]);

Related

The Select/Unselect all are not working in Kartik select2 yii2

I have selecting, unselect and unselecting event. But when I click on select all or unselect all none of these events are called.
Every thing is working find except the select/Unslect all issue.Here is my code
echo $form->field($model, 'partnersIn')->widget(Select2::class, [
'name' => 'partnersIn[]',
'data' => Partner::PartnersData(),
'theme' => Select2::THEME_BOOTSTRAP,
'options' => ['value' => $partners, 'placeholder' => Yii::t(
'app',
'Select the partners to show ad'
)],
'pluginOptions' => [
'tags' => true,
'allowClear' => true,
'multiple' => true,
],
])->label('Partners');
?>
Please run the composer update or composer install command.
Its work for me

Yii2 DynaGrid - how to hide formats from export menu

How to hide some formats from export menu in DynaGrid. I was tried settings for GridView widget but doesn't work. Formats are still visible.
'exportConfig' => [
GridView::CSV => ['label' => 'Save as CSV'],
GridView::HTML => [],
GridView::PDF => [],
]
You need to use the above option exportConfig under the gridOptions and you should specify only those formats that you want to be visible once the dropdown opens, if you want only the CSV format then just provide the CSV option under the exportConfig
echo DynaGrid::widget([
'columns' => $columns,
'storage' => DynaGrid::TYPE_COOKIE,
'theme' => 'panel-danger',
'gridOptions' => [
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'exportConfig'=>[
GridView::CSV=>['label'=>'Save As'],
],
'panel' => ['heading' => '<h3 class="panel-title">Library</h3>'],
],
'options' => ['id' => 'dynagrid-1'], // a unique identifier is important
]);

How to allow DIV tags in Yii2 Editor

I installed a blog module that allows me to add blogs to my Yii2 app. Everything works well except the editor. I think Yii2 by default uses redactor.
The problem is that when I add code with using the code interface, all DIV tags are converted automatically to P tags.
I have checked through the redactor configuration but it does not look like there is a setting to adjust this:
'redactor' => [
'class' => 'yii\redactor\RedactorModule',
'uploadDir' => '#frontend/images/blog/upload',
'uploadUrl' => '/sites/eop/frontend/images/blog/upload',
'imageAllowExtensions' => ['jpg', 'png', 'gif', 'svg'],
],
Any idea on where else to look at?
You need to use the replaceDivs option, and set it to false under the client options. See the below code for an example
<?php echo \yii\redactor\widgets\Redactor::widget(
[
'model' => $model,
'attribute' => 'body',
'clientOptions' => [
'replaceDivs' => false
]
]
);
?>
if you are using an ActiveForm it should be like
<?php echo $form->field($model, 'body')->widget(
[
'clientOptions' => [
'replaceDivs' => false
]
]
);
?>

Yii2 kartik Form Builder + INPUT_WIDGET + NumberControl

I want to use widget NumberControl in kartik's Form Bulder. But when I try this code, i have an empty form and there no errors. Couse I can't understand where is my mistake.
Please tell me if someone use a NumberControl in kartik's Form Builder.
use kartik\builder\Form;
echo Form::widget([
'model' => $model,
'form' => $form,
'columns' => 6,
'columnSize' => 'md',
'attributes' => [
'oi_count' => [
'type' => Form::INPUT_WIDGET,
'widgetClass' => '\kartik\number\NumberControl',
],
]
]);
According to this:https://demosbs3.krajee.com/number by default the type is "hidden", you should set it to "text".

yii2 checkboxList custom class

Here is the sample code from Yii2 checkboxList, I want to add custom class for each Item in checkboxList but I don't know how and where can I add that!
Could you please help me please ..
$list = [0 => 'PHP', 1 => 'MySQL', 2 => 'Javascript'];
$list2 = [0,2];
echo Html::checkboxList('CuisineId',$list2,$list,array('class' => 'test' ));
Thanks in advance.
If you want to add the same class, you should use itemOptions :
echo Html::checkboxList('CuisineId', $list2, $list, ['itemOptions'=>['class' => 'test']]);
Or if you want a custom class for each item, you should use item callback :
echo Html::checkboxList('CuisineId', $list2, $list, ['item'=>function ($index, $label, $name, $checked, $value){
return Html::checkbox($name, $checked, [
'value' => $value,
'label' => $label,
'class' => 'any class',
]);
}]);
Read more : http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#checkboxList()-detail
EDIT : add example
Just in case you only need to change the label options:
<?= Html::checkboxList('CuisineId', $list, $items, [
'itemOptions' => [
'labelOptions' => [
'style' => 'font-weight: normal',
'class' => 'some-custom-class',
],
],
]) ?>
Note: Everything you put inside itemOptions will be passed to Html::checkbox() as its own options when creating each checkbox. It means you can pass class, style, label, labelOptions, etc.