Yii2 Summernote widget not working - yii2

Hello Friends I installed summernote widget through composer. It works fine but some of the options are not working. I mention it in the following image:
Please help me if you have any idea how to enable it thanks
This is my code:
<?= $form->field($model, 'remarks')->widget(Summernote::className(), [
'clientOptions' => [
]
])->label(false); ?>

Related

Yii2 how to format <sup> tags in forms and GridView?

I have an attributeLabels for an attribute that has a <sup> tag:
public function attributeLabels() {
return [
'density' => Yii::t('yii', 'density (kg/dm<sup>3</sup>)'),
];
}
In the view it looks appropriate, but in the form and in the GridView as label it's simply like (kg/dm<sup>3</sup>)
I have tried to add labelOptions with many different format values to it, but no luck.
<?= $form->field($model, 'density', ['labelOptions' => ['format' => '(html/text/raw etc.)']])->textInput() ?>
Is it possible to make it look like a real <sup> (kg/dm3) text in the form, and if yes, can you please tell me how? Thank you.
Call it like that:
<?= $model->getAttributeLabel('density'); ?>
<?= $form->field($model, 'density')->textinput()->label(false) ?>
and after that format your template
Edit (better way):
<?= $form->field($model, 'density', ['labelOptions' => ['label' => $model->getAttributeLabel('density')]])->textinput() ?>

How to display a HTML tag in Yii2 form error summary

I am trying to display a link in error message in login for, but it is not working.
The error message in LoginForm valdiation:
$this->addError($attribute, 'Your account has been disabled. Enable It');
In login.php (view):
<?= $form->errorSummary($model); ?>
I tried like below, but not working:
<?= $form->errorSummary($model,['errorOptions' => ['encode' => false,'class' => 'help-block']]); ?>
I am getting the following output instead of rendered a tag:
You need to disable encoding at ActiveForm level using encodeErrorSummary property, if you want to use $form->errorSummary($model):
<?= $form = ActiveForm::begin([
'id' => 'login-form',
'encodeErrorSummary' => false,
'errorSummaryCssClass' => 'help-block',
]) ?>
<?= $form->errorSummary($model) ?>
Alternatively you may use Html::errorSummary() directly:
<?= Html::errorSummary($model, ['encode' => false]) ?>

Html::img tag not working in yii2

I am new to yii2 and I am trying to add images to my website with the help of Html::img tag but I keep getting broken links on the website. I am using wamp. This is my code:
<?= Html::img('#web/images/logo.png', ['alt' => 'My logo']) ?>
Thanks for the help.
You should conver to an url your alias
use yii\helpers\Url;
...
<?= Html::img( Url::to('#web/images/logo.png'), ['alt' => 'My logo']) ?>
Try this
<?php $domain = yii\helpers\Url::base(true);
echo Html::img($domain.'/images/logo.png', ['alt' => 'My logo'])
?>

Confirm message not working on postLink with icon

I need some help with a postLink created with FormHelper in CakePHP 3. The normal postLink works just fine like this:
<?= $this->Form->postLink(__('Delete'),
['action' => 'delete', $member->id],
['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>
But when I try to use a font-awesome icon / i-tag instead of the text link, the confirmation message is not showing up anymore. The icon itself is showing correctly and the action still works fine, just the message is not working.
I used the following posts for help, but the examples in the answers there are not working for me:
CakePHP equivalent of html code
CakePHP delete confirmation
I tried these two approaches:
<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
['action' => 'delete', $member->id],
['escape' => false],
['confirm' => __('Are you sure, you want to delete {0}?', $member->name)]) ?>
<?= $this->Form->postLink(
$this->Html->tag('i', '', ['class' => 'fa fa-trash']),
['action' => 'edit', $member->id],
['escape' => false],
['confirm' => __('Are you sure you want to delete {0}?', $member->name)]); ?>
I'm still very new to CakePHP and tried to look this up in the book, but that did not help me. I also tried the exact syntax as shown in the SO links above, which seemingly worked for some others...but the confirmation message is still not working for me.
What am I doing wrong here?
escape and confirm options should be in the same array. Function postLink() looks like this:
postLink(string $title, mixed $url = null, array $options =[])
So working code for you will be:
<?= $this->Form->postLink('<i class="fa fa-trash"></i> ',
['action' => 'delete', $member->id],
[
'escape' => false,
'confirm' => __('Are you sure, you want to delete {0}?', $member->name)
]
) ?>

How to use datepicker in yii2 basic?

I want to use yii2 datepicker but I'm having trouble to implement this. It does not show the date picker and I don't know what is missing in my code. I'm still new in this yii
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<div class="row">
<div class="col-lg-6">
<div class="myproj-index">
<?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>
<? //$form->field($model, 'periodfrom')
echo DatePicker::widget([
'model' => $model,
'attribute' => 'periodfrom',
'language' => 'en',
'dateFormat' => 'yyyy-MM-dd',
]);
?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
Edit
I downloaded this file here jui
I found out that in my file I have no jui folder under yiisoft folder. My question in appasset how can I declare this files ?
Answer
I fixed it, I downloaded the jquery-ui files then added them to the bower folder in yii2.
First install this extension through composer.
run: php composer.phar require --prefer-dist yiisoft/yii2-jui "*" in your project directory.
update composer.
In your view file use use yii\jui\DatePicker;.
You probably did not install Datepicker in the vendor package.
Thanks.
Do you have use .....\DatePicker; ?
Also are you including the jui asset and everything, take a look at the source, do you have jui and all the JS included?
Edit:
Have you done a "composer update" lately?
Use this code if you are using kartik datetime picker
<?= $form->field($model, 'date')->widget(DatePicker::classname(),['options' => ['placeholder' => 'Enter event time ...'],'pluginOptions' => [....]]) ?>