yii2 : how to change language of ckeditor - yii2

i used use dosamigos\ckeditor\CKEditor in my project in yii2
i want change language of ckeditor in config !
how can i solve my problem?
this is my code in _form.php
<?php
use dosamigos\ckeditor\CKEditor;
<?=
$form->field($model, 'text')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
// 'language' => 'fa',
'preset' => 'full'
])
?>

You have to use clientOptions property:
$form->field($model, 'text')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'clientOptions' => ['language' => 'fa'], // here
'preset' => 'full'
])

Related

yii2 render remaining character in form field

I use jlorente remainingcharacters widget to show remaining character countdown for Inputfield in _form.php:
<?= $form->field($model, 'char52', ['showLabels'=>true])->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [
'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'counter',
'invalidClass' => 'error'
],
'options' => [
'rows' => '1',
'class' => 'col-md-12',
'maxlength' => 52,
'placeholder' => Yii::t('app', 'Write something')
]
]) ?>
<?= $form->field($model, 'text', ['showLabels'=>true])->widget(\dosamigos\ckeditor\CKEditor::className(), [
'options' => ['rows' => 1],
'preset' => 'full'
]) ?>
As I rendered form fields the height of textInput is not the same as standard.
Is there any solution for this problem.
I am also searching for other widgets for remaining charachters as I want to use kartik\form\ActiveForm for rendering on the same text input remaining charachter count and ActiveField Prepend Addon.
Try adding "form-control" class to your widget:
'options' => [
...
'class' => 'col-md-12 form-control',
...
]

change yii2 kartik fileInput language not working

I have a problem with kartik's FileInput widget.
I want to change the language but it's not working here is my code
<?php
use kartik\file\FileInput;
echo $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [
'options' => ['multiple' => true, 'accept' => 'image/*'],
'pluginOptions' => [
'uploadUrl' => Url::to(['upload-images']),
'language' => substr(\Yii::$app->language, 0, 2),
]
]);
the language is set to "fr-FR" but I'm still getting texts in english
why? what did I miss?
thank you
well then I found the solution, it's kind of tricky though
```php
<?php
echo $form->field($model, 'imageFiles[]')->widget(FileInput::classname(), [
'options' => ['multiple' => true, 'accept' => 'image/*'],
'language' => 'fr',
'pluginOptions' => [
'uploadUrl' => Url::to(['upload-images']),
'language' => substr(\Yii::$app->language, 0, 2),
'browseLabel' => Yii::t('app', 'Sélectionnez'),
'dropZoneTitle' => Yii::t('app', 'Glissez et déposez les fichiers ici...')
]
]);
?>
```

Kartiv yii2 datepicker with model and custom id

I am using kartik datepicker extension http://demos.krajee.com/widget-details/datepicker in Yii2.
Issue :
If I use this with custom id for input it does not show show model validations
echo kartik\date\DatePicker::widget([
'model' => $objPatientModel,
'form'=>$objActiveForm,
'attribute' => 'date_of_birth',
'options' => ['placeholder' => 'Enter birth date ...', 'id' => 'patient_dob'], **// with id clientside validations for model does not work**
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'endDate' => date('d-m-Y'),
]
]);
While below code works
echo kartik\date\DatePicker::widget([
'model' => $objPatientModel,
'form'=>$objActiveForm,
'attribute' => 'date_of_birth',
'options' => ['placeholder' => 'Enter birth date ...'],**//id is not used here**
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'endDate' => date('d-m-Y'),
]
]);
But I want to use custom id .Any suggestions ?
You have to override the selectors, example:
$form->field($model, 'comment', ['selectors' => ['input' => '#myCustomId']])
->textarea(['id' => 'myCustomId']);?>
See https://github.com/yiisoft/yii2/issues/7627
<?=
$form->field($model, 'sales_date')->widget(DateControl::classname(), [
'name' => 'sales_date',
'value' => date('d-m-Y h:i:s'),
'type' => DateControl::FORMAT_DATETIME,
'autoWidget' => true,
'displayFormat' => 'php:d-m-Y h:i:s',
'saveFormat' => 'php:Y-m-d h:i:s',
'saveOptions' => [
'type' => 'hidden',
'form' => 'sales-form-red',
],
])
?>
by using the following option you can add extra form tag to input
'saveOptions' => [
'type' => 'hidden',
'form' => 'sales-form-red',
'class' => 'sales_date',
]
In my case out was
<input type="hidden" id="sales-sales_date" name="Sales[sales_date]" form="sales-form-red">
check by using link
Date Control Demo

Yii2-editable-widget. Doesn't work with few widgets

I'm using editable widget (2amigos/yii2-editable-widget or kartik-v/yii2-editable). It works fine, but when I try it in foreach it works with first element only. I want to use a several widgets for a model. How can I solve it?
Here is the code:
foreach ($models as $model) {
echo Editable::widget( [
'model' => $model,
'attribute' => 'name',
'url' => 'site/rename',
'type' => 'text',
'mode' => 'pop',
'clientOptions' => [
' pk' => $model->id,
]
]);
}
I guess you have to set a unique id for each Editable Widget. Look how the js code for the widget is embedded.
e.g. if you use kartiks widget
echo Editable::widget([
'model' => $model,
'attribute' => 'name',
'type' => 'primary',
'size'=> 'lg',
'inputType' => Editable::INPUT_TEXT,
'editableValueOptions' => ['class' => 'text-success h3'],
'options'=> [
'id'=>'name-editable'.uniqid(),
]
]);

Where is the Yii2 autocomplete class located?

I have used:
echo AutoComplete::widget([
'name' => 'file',
'clientOptions' => [
'source' => ['USA', 'RUS'],
],
]);
But I get the error:
Class 'AutoComplete' not found.
You should install Yii 2 Jquery UI extension first.
The full class name with namespace is yii\jui\Autocomplete.
You can use it like this:
use yii\jui\Autocomplete;
...
echo AutoComplete::widget([
'name' => 'file',
'clientOptions' => [
'source' => ['USA', 'RUS'],
],
]);
or
echo yii\jui\AutoComplete::widget([
'name' => 'file',
'clientOptions' => [
'source' => ['USA', 'RUS'],
],
]);