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

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);
?>

Related

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 kartik input widget not working properly

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.

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 ...',
]
]);

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,
],
]);

Yii2 Unknown Property Exception in Server

I have a view displaying a grid view for a particular model. In my local machine, it's working well but when I deploy the application to another server, an attribute is not found hence the Unknown Property Exception. When I look at the code though, the attribute is there.
Any ideas?
Here is the model class code: http://codebin.org/view/f0a713c1
The view code:
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
[
'attribute' => 'is_condemned',
'label' => 'Condemned',
'class' => '\kartik\grid\BooleanColumn',
'falseLabel' => 'Active',
'trueLabel' => 'Condemned'
],
],
// set your toolbar
'toolbar' => [
['content' =>
Html::a(FA::icon('plus') . ' Add', ['/equipment/default/create'], ['class' => 'btn btn-success'])
],
'{export}',
'{toggleData}',
],
// set export properties
'export' => [
'fontAwesome' => true,
'filename' => 'equipment-export-'.time(),
'exportConfig' => [
'html' => ['showCaption' => FALSE],
'pdf' => ['showCaption' => FALSE],
],
],
'bordered' => TRUE,
'striped' => TRUE,
'condensed' => TRUE,
'responsive' => TRUE,
'hover' => TRUE,
'showPageSummary' => TRUE,
'panel' => [
'type' => GridView::TYPE_PRIMARY,
'heading' => '',
],
'persistResize' => false,
]);
The reason why it wasn't working was that the model class being imported was in lowercase. Apparently, I entered the wrong value in gii. It was just in the other servers that it was case-sensitive.
Could be either a problem with case (Uppercase, lowercase) in the namespace or in the class name or backslash path problem (/, \). In this case the class is not found and Yii shows this message.

Categories