How to change error message text in kartik fileinput - yii2

I am using kartik yii2 widget fileinput. I set 'maxFileSize' to 1024. When uploaded file exceeds maximum allowed size, error message shows up, I want to change this error text and show it in Georgian language. How can I achieve this?
Here is my code:
<?= $form->field($model, 'photo_name')->widget(FileInput::classname(), [
'options'=>[
'id'=>'upload-img',
'multiple'=>false,
'accept'=>'image/*',
],
'pluginOptions'=>[
'allowedFileExtensions'=>['jpg', 'gif', 'png', 'bmp'],
'browseLabel'=>'browse',
'captionLabel'=> '',
'removeLabel'=>'remove',
'browseClass' => 'btn btn-success',
'uploadClass' => 'btn btn-info',
'removeClass' => 'btn btn-danger',
'showPreview' => true,
'showCaption' => false,
'showRemove' => true,
'showUpload' => false,
'overwriteInitial'=>false,
'dropZoneEnabled'=>false,
'showClose' => false,
'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
'maxFileSize'=>1024
],
]); ?>
I need to change this error message:

You just need add this line into 'pluginOptions' and custom it:
<?= $form->field($model, 'photo_name')->widget(FileInput::classname(), [
'options'=>[
'id'=>'upload-img',
'multiple'=>false,
'accept'=>'image/*',
],
'pluginOptions'=>[
.
.
.
'msgSizeTooLarge' => 'File "{name}" (<b>{size} KB</b>) exceeds maximum allowed upload size of <b>{maxSize} KB</b>.',
],
]); ?>

You need to use the tooBig option inside the model validation rule where you specify the maxSize of the file your rule should look like below
[[ 'photo_name'] , 'file' , 'extensions' => 'pdf, jpg' , 'maxSize' => 1024000 , 'tooBig' => 'Limit is 1024KB' ] ,
For displaying it in georgian or any other than english you should look into the Message Translation

Related

Yii2 logout Method Not Allowed (#405)

I'm using adminlte advanced template for backend. I want to add logout in the left column.
I've read other posts and I understand I've to add data method post. I've added it in following line in left.php file, but it doesn't work. How to make it work?
<?= dmstr\widgets\Menu::widget(
[
'options' => ['class' => 'sidebar-menu tree', 'data-widget'=> 'tree'],
'items' => [
['label' => 'Logout', 'icon' => 'file-code-o', 'url' => ['/site/logout'], 'data-method'=>'post'],
]
) ?>
It is extending the yii\widgets\Menu and you need to specify the template to modify or add any attribute to the link as the data-method="post" needs to be added to your link you should change the code to the following
echo
dmstr\widgets\Menu::widget(
[
'options' => ['class' => 'sidebar-menu tree', 'data-widget'=> 'tree'],
'items' => [
['label' => 'Logout', 'icon' => 'file-code-o', 'url' => ['/site/logout'], 'template'=>'{label}'],
]
);
You can add a form in to your click field:
$items[] = [
[
'label' => 'Logout',
'icon' => 'file-code-o',
'url' => ['/site/logout'],
'template' => Html::beginForm(array('site/logout')) .
Html::submitButton('Logout') . Html::endForm(),
],
];

Remove encoding for popovers on labels

I'm using Yii2 to generate a popover on a label, but having some trouble to remove the default HTML encoding. I'm not sure that the popover can be created for just the label without HTML encoding and what the correct way to do this is, it must be possible though as Gii uses some variant of this code? This is what I've tried:
<?= $form->field($model, 'function')->textInput(['maxlength' => true])
->label(null, [
'class' => 'dashed-line',
'data-toggle' => 'popover',
'data-content' => 'This will be ran through <code>strtolower()</code>',
'data-placement' => 'right',
'encodeLabel'=> false]) ?>
Use
['labelOptions' => ['encode' => false]]
.
<?= $form->field($model, ['labelOptions' => ['encode' => false]] ,
'function')->textInput(['maxlength' => true])
->label(null, [
'class' => 'dashed-line',
'data-toggle' => 'popover',
'data-content' => 'This will be ran through <code>strtolower()</code>',
'data-placement' => 'right',
) ?>
you can use label option for setting the encode false of label attribute
<?= $form->field($model,
'function')->textInput(['maxlength' => true])
->label(null, [
'class' => 'dashed-line',
'data-toggle' => 'popover',
'data-content' => 'This will be ran through <code>strtolower()</code>',
'data-placement' => 'right',
'encode' => false,
) ?>

Yii2 Redactor is not loaded after ajax/pjax request

I use redactor for editing comment. There are multiple redactors since there are multiple comments. Most of the time, redactor is loaded, but sometimes the redactor is not loaded and only generate normal text editor.
These comments are loaded after Pjax Request
My code:
<?= \yii\redactor\widgets\Redactor::widget([
'name' => 'comment',
'value' => \yii\helpers\HtmlPurifier::process($comment),
'clientOptions' => [
'imageUpload' => \yii\helpers\Url::to(['/redactor/upload/image']),
],
]) ?>
Problem solved:
You have to put ID :)
<?= \yii\redactor\widgets\Redactor::widget([
'id' => 'edit_redactor_' . $comment_id,
'name' => 'comment',
'value' => \yii\helpers\HtmlPurifier::process($comment),
'clientOptions' => [
'imageUpload' => \yii\helpers\Url::to(['/redactor/upload/image']),
],
]) ?>

Yii 2 Editable, how to use editable inside form?

$form = ActiveForm::begin();
..
echo Editable::widget([ //this break outter form, because this generate another form
'name'=>'person_name',
'asPopover' => true,
'value' => 'Kartik Visweswaran',
'header' => 'Name',
'size'=>'md',
'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...']
]);
ActiveForm::end();
So, I tried,
echo Form::widget([
'model'=>$model,
'form'=>$form,
'columns'=>1,
'attributes'=>[
'title'=>[
'label'=>false,
'type' => Editable::INPUT_TEXT,
'widgetClass' => Editable::className(),
'options' => [
'asPopover' => true,
]
],
]
]);
but, it shows input box all the time, not editable text.
how can I use editable widget inside form? without breaking outter form?
You can try this way:
<?= $form->field($model, 'person_name')->Editable::widget([
'name'=>'person_name',
'asPopover' => true,
'value' => 'value',
'header' => 'Name',
'size'=>'md',
'options' => ['class'=>'form-control', 'placeholder'=>'Enter person name...']
]);
?>
Note : Not tested yet.

can use yii2 DepDrop::widget without model?

all developer kartik\DepDrop widget The ability to use without model
My code this but error
use kartik\widgets\DepDrop;
<?php echo DepDrop::widget([
'options' => ['id'=>'customer-city'],
'pluginOptions' => [
'depends => ['province'],
'placeholder => 'select ...',
'url' => Url::to(['/site/city'])
]
]); ?>
I use this code for show dropdown without lable
Yes, for it you need set the attribute name:
<?php echo DepDrop::widget([
'name' => 'city',
'options' => ['id'=>'customer-city'],
'pluginOptions' => [
'depends' => ['province'],
'placeholder' => 'select ...',
'url' => Url::to(['/site/city'])
]
]); ?>