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...')
]
]);
?>
```
Related
I've used Froala editor in my Yii2 application. While saving content to database column question it is added with HTML tags. How can I disable that option, I just want to save the content as it is?
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([
'model' => $model,
'attribute' => 'question',
'options' => [
// html attributes
'id'=>'question'
],
'clientOptions' => [
'toolbarInline' => false,
'theme' => 'royal', //optional: dark, red, gray, royal
'language' => 'en_gb' // optional: ar, bs, cs, da, de, en_ca, en_gb, en_us ...
]
]); ?>
Try this:
<?php echo froala\froalaeditor\FroalaEditorWidget::widget([
'model' => $model,
'attribute' => 'question',
'options' => [
// html attributes
'id'=>'question'
],
'clientOptions' => [
'toolbarInline' => false,
'theme' => 'royal', //optional: dark, red, gray, royal
'language' => 'en_gb',
'entities' => '', // <- this
]
]); ?>
https://www.froala.com/wysiwyg-editor/docs/options#entities
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'
])
In my model I use DateValidation
['date_birthday', 'date', 'format' => 'd.m.yy', 'min' => '01.01.1900', 'max' => date('d.m.yy'), 'tooSmall'=>'The date is from past. Try another','tooBig' => 'The date is from future. Try another', 'message' => 'Try to input the date'],
In view I call the widget
<?php echo $form->field($modelForm, 'date_birthday')->widget(\kartik\date\DatePicker::classname(), [
'type' => \kartik\date\DatePicker::TYPE_COMPONENT_APPEND,
'pickerButton' => false,
'options' => [
'placeholder' => '',
],
'pluginOptions' => [
'format' => 'dd.mm.yyyy',
'autoclose' => true,
'showMeridian' => true,
'startView' => 2,
'minView' => 2,
]
]) ?>
It checks for min and max dates, but show no error message. I think its because of different date formats in model and view. How to fix it?
If you submit form you will see error messages. According to this issue https://github.com/yiisoft/yii2/issues/7745 yii2 have not client-side validations of date
You can enable ajax validation. Add in create and update action before if statement
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
And add use yii\widgets\ActiveForm; on the top of controller class. In your _form.php file enable ajax for whole form
<?php $form = ActiveForm::begin([
'enableAjaxValidation' => true,
]); ?>
, or for the field only
<?php echo $form->field($model, 'date_birthday', ['enableAjaxValidation' => true])->widget(\kartik\date\DatePicker::classname(), [
...
Also, you can add plugin options for limit date with startDate and endDate (https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#startdate)
<?php echo $form->field($model, 'date_birthday', ['enableAjaxValidation' => true])->widget(\kartik\date\DatePicker::classname(), [
'type' => \kartik\date\DatePicker::TYPE_COMPONENT_APPEND,
'pickerButton' => false,
'options' => [
'placeholder' => '',
],
'pluginOptions' => [
'format' => 'dd.mm.yyyy',
'autoclose' => true,
'showMeridian' => true,
'startView' => 2,
'minView' => 2,
'startDate' => '01.01.1900',
'endDate' => date('d.m.Y'),
]
]) ?>
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
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(),
]
]);