yii2 kartik input widget not working properly - php

I added buttons for delete and drag but not working, my code in the view:
<?= $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [
'options' => ['multiple' => true, 'accept' => 'image/*',
'id'=>'inputFile'],
'pluginOptions' => [
'rtl'=>'true',
'fileActionSettings'=>['showZoom'=>true, 'showRemove' =>true,
'showDrag'=>true],
'previewFileType' => 'image',
'maxFileCount' => 4,
'showUpload' => false,
]
]);
Where are i making mistakes?

When using FORM submission mode (without uploadUrl). in this scenario you cannot REMOVE preview thumbnails before they are uploaded - ONE by ONE (you can only clear all - this is a native HTML FILE input limitation as one cannot edit the files in the input). in this case we must add uploadUrl:
<?= $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [
'options' => ['multiple' => true, 'accept' => 'image/*',
'id'=>'inputFile'],
'pluginOptions' => [
'uploadUrl' => '/site/index',
'rtl'=>'true',
'fileActionSettings'=>['showZoom'=>true, 'showRemove' =>true,
'showDrag'=>true],
'previewFileType' => 'image',
'maxFileCount' => 4,
'showUpload' => false,
]
]);
This is ajax submission mode with uploadUrl.

Related

Yii2 Active form image uploading validation issue at the time of edit

I am uploading a file(image and video) using Active form in yii2. At the time of creating validation work great but when I try to open them in edit mode and i already have an image just I'm showing the uploaded image preview.
But when I try to submit the form it is showing please select the image.. I want to skip the validation when I have an image in the preview.
echo $form->field($model, 'banner')->widget(FileInput::classname(), [
'options' => ['accept' => 'image/*', 'multiple' => false],
'pluginOptions' => [
'initialPreview' => $initial_preview_image,
'validateInitialCount' => true,
'initialPreviewAsData' => true,
'initialPreviewConfig' => $initial_preview_image_config,
'allowedFileExtensions' => ['png', 'jpg', 'jpeg'],
'maxFileCount' => 1,
'showUpload' => false,
'showRemove' => $showRemove,
],
// 'pluginEvents' => []
]);

Kartik Select2 load ajax when other input change value

I need to load data with ajax to a Kartik Select2 but only when certain input changes values. Kind of like...
<?= $form->field($model, 'id_list')->widget(Select2::classname(), [
'data' => [],
'theme' => Select2::THEME_BOOTSTRAP,
'options' => [
'placeholder' => 'List',
],
'pluginOptions' => [
'allowClear' => true,
'action' => '#input_first'.change // or something
'ajax' => [
'url' => Url::to(['/list']),
'dataType' => 'json',
'data' => new JsExpression('function(params) { return {q:params.term}; }')
],
],
]);?>
Have you tried to use Select2 with DepDrop plugin (http://demos.krajee.com/widget-details/depdrop)?

Yii2 required validation rule on "select2" widget

I'm using kartik select2 widget in Yii2 framework. Required validation rule doesn't work on it.
Here is my view code:
$form->field($model, 'city')->widget(\kartik\select2\Select2::classname(), [
'data' => $cities,
'options' => [
'class' => 'form-control',
'placeholder' => 'Please select city...',
'multiple' => false,
],
'pluginOptions' => [
'allowClear' => true
],
])->label('City');
Here is my model rule code:
[['city'], 'required'],
[['city'], 'integer']
Any idea to make the dropdown required?
Use this in plugin option
pluginOptions' => [
'initialize' => true,
],
This is working code for me
$form->field($model, 'tech_type')->widget(Select2::classname(), [
'options'=>['id'=>'tech-id'],
'data' => ArrayHelper::map(Techtypes::find()->asArray()->all(), 'tech_id', 'tech_type'),
'pluginOptions'=>[
'initialize' => true,
'placeholder' => 'Select Technician Type ...',
]
]);

How do I can remove the label above input file form?

I've an application that was developed using Yii2, and this application I've use Kartik Input File for upload file.
Case
From the example above, I want to remove / hide the "File" label.
And I think, that label based on model name.
This is the code I use:
<?=
$form->field($model, 'file')->widget(FileInput::classname(), [
'options' => [
'accept' => 'doc/*', 'file/*',
'enableLabel' => false,
],
'pluginOptions' => [
'allowedFileExtensions' => ['csv', 'xls', 'xlsx'],
'showUpload' => FALSE,
'showPreview' => FALSE,
]
]);
?>
How do I can remove the label above?
Thanks
For removing the label you can simply use the following:
<?=
$form->field($model, 'file')->widget(FileInput::classname(), [
'options' => [
'accept' => 'doc/*', 'file/*',
'enableLabel' => false,
],
'pluginOptions' => [
'allowedFileExtensions' => ['csv', 'xls', 'xlsx'],
'showUpload' => FALSE,
'showPreview' => FALSE,
]
])->label(false);
?>

Yii2 kartik datepicker multiple inline

I want a Datepicker inline with multidate enabled.
It is rendered correctly but returns only the last selected date.
Return value: '12.11.2016'
If I set 'type' to TYPE_INPUT everything is working fine.
Expected return Value: '23.11.2016, 24.11.2016, 18.11.2016, 12.11.2016'
<?= $form->field($model, 'dateString')->widget(DatePicker::className(), [
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'multidate' => true,
],
]);
?>
I'm using "kartik-v/yii2-widget-datepicker": "#dev" and the model is a ActiveRecord Model.
Seems to have been fixed with this commit: https://github.com/kartik-v/yii2-widget-datepicker/commit/39e0e71277d0f115341e118a2b879a0dfcbd01c3
This will solve the problem
echo $form->field($model, 'date_time')->widget(DatePicker::classname(), [
'options' => [
'value' => "Jul-11-2020,Jul-14-2021,Jul-12-2020",
'class' => "col-md-12 form-control picker"
],
'readonly' => false,
'language' => 'en',
'type' => DatePicker::TYPE_INLINE,
'pluginOptions' => [
'format' => 'M-dd-yyyy',
'todayHighlight' => true,
'multidate' => true,
],
]);

Categories