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']),
],
]) ?>
Related
i have a depdrop in my project like
<?= $form->field($model, 'neighborhood_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map($query,'id','placeWithCity'),
'options' => ['placeholder' => 'Select Your Neighborhood','id'=>'select_place'],
])->label(false); ?>
And
<?=$form->field($model, 'building_id')->widget(DepDrop::classname(), [
'data' =>ArrayHelper::map(Buildings::find()->all(),'id','buildingWithPlace'),
'options' => ['placeholder' => 'Select The Building','id'=>'select_building'],
'type' => DepDrop::TYPE_SELECT2,
'pluginOptions' => [
'depends' => ['select_place'],
'url'=>Url::to(['property-commercial-rent/buildings']),
'loadingText' => 'Loading buildings ...',
]
])->label(false);?>
The second dropdown is depend on the first one.Initially they both have full list of data without any filtering.When i select a neighborhood in the first dropdown then the second populates with the building names under that neighborhood. Then i have a reset button like and has an action like
$( "#reset-location" ).click(function() {
$(select_place).val('').trigger('change');
$(select_building).val('').trigger('change');
});
And this click resetting the both select.BUt the problem is the building has only the items under the previously select neighborhood.I want the make it all like initial stage.How can i do this
You don't need a reset button. On the neighbourhood field allow clear, so it would be like this
<?= $form->field($model, 'neighborhood_id')->widget(Select2::classname(), [
'data' => ArrayHelper::map($query,'id','placeWithCity'),
'options' => ['placeholder' => 'Select Your Neighborhood','id'=>'select_place'],
'pluginOptions' => [
'allowClear' => true
],
])->label(false); ?>
Then there will be a x in the field to clear it.
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(),
],
];
In my yii2 project, I'm using Pjax GridView.
My index page:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'batch',
[
'attribute' => 'file_import',
'format' => 'raw',
'value'=>function ($data) {
return Html::a($data->file_import, ['/device/index', 'DeviceSearch', 'batch' => $data->batch]);
},
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
The link in the file_import column goes to http://localhost/index.php/device/index?1=DeviceSearch&batch=200325806610154437. But in this url, all the data is showing instead of showing only the search result. I wanted to set the file_import column as an url which will show only the search result by the provided parameter in the url.
Thank you in advance.
Change URL route to
['/device/index', 'DeviceSearch[batch]' => $data->batch]
$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.
I am using 2 amigos ckeditor widget
<?= $form->field($model, 'text')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic'
]) ?>
How do I add the configuration settings, I want the editor to accept HTML tags hTML and body which the editor usually stripes off. Where do i specify this setings in the widget.
There is special property called clientOptions for setting plugin options.
For filtering tags use allowedContent option, you can read official docs here.
Here is an example of code:
<?= $form->field($model, 'text')->widget(CKEditor::className(), [
'options' => ['rows' => 6],
'preset' => 'basic',
'clientOptions' => [
'allowedContent' => ...,
],
]) ?>
So i added the configuration 'allowedContent' => true and it worked.