I have this code for the column grid Descrizione in my view file:
[
'attribute' => 'Descrizione',
'format' => 'html',
'label' => 'Descrizione',
],
The problem is that for the field Descrizione don't read the <br> element. For example, in the database the field is set like Today is<br>a better day, meanwhile in the view show the field without <br> (Today is a better day). I want that the field in the view respect the format when there is a <br>. Is already set with 'format' => 'html' but this don't works.
Any suggestion?
You can get the same with ntext
[
'attribute' => 'Descrizione',
'format' => 'ntext',
'label' => 'Descrizione',
],
If you need some extra markup to be displayed, you can use this:
'format' => 'raw',
Related
I have the following:
Html::a('Link', ['some/route'], [
'class' => 'btn btn-lg btn-primary', // WORKS
'style' => 'padding: 100px;', // WORKS
'data-id' => 123, // DOES NOT WORK
'data' => [
'id' => 123, // DOES NOT WORK
],
]);
As per docs, both of the specified data-* attributes in Html::a helper should render their respective attributes in the HTML output, but they do not, and I do not understand why.
Yii 2 documentation on renderTagAttributes also states the following:
Renders the HTML tag attributes.
Attributes whose values are of boolean type will be treated as boolean
attributes.
Attributes whose values are null will not be rendered.
The values of attributes will be HTML-encoded using encode().
The "data" attribute is specially handled when it is receiving an
array value. In this case, the array will be "expanded" and a list
data attributes will be rendered. For example, if 'data' => ['id' =>
1, 'name' => 'yii'], then this will be rendered: data-id="1"
data-name="yii". Additionally 'data' => ['params' => ['id' => 1,
'name' => 'yii'], 'status' => 'ok'] will be rendered as:
data-params='{"id":1,"name":"yii"}' data-status="ok".
EDIT: I am trying to do this inside GridView column.
Okay, since I have used Html::a inside a GridView column, you will have to change the output format of that column. html will not work for data attributes, so you will need to switch to raw:
[
'label' => 'Actions',
'format' => 'raw',
'value' => function($model) {
return Html::a('Link', ['some/route'], [
'class' => 'btn btn-lg btn-primary', // WORKS
'style' => 'padding: 100px;', // WORKS
'data-id' => 123, // WORKS
'data' => [
'id-second' => 123, // WORKS
],
]);
},
]
This is my form. I have save value when I create but then when I update the value wont appear.
$form->field($model, 'unit_id')->widget(Select2::classname(), [
'data' => $getunit,
'language' => 'en',
'value'=>$model->unit_id, //cant work
'initValueText'=>$model->unit_id //cant work
'options' => ['placeholder' => 'Select','multiple'=>true,'value'=>$model->unit_id' //cant work ],
'pluginOptions' => [
'allowClear' => true,
'tags'=>true,
'maximumInputLength'=>10,
],
])->label(false)
Anyone know why? I search through online but I still cant solve it
I'm trying to display category values according to it's name, not id. I'm trying to do like so:
[
'attribute' => 'category_id',
'value' => 'category.name',
],
But then attribute doesn't get displayed. It displays: name instead of Category. Category name is displayed correctly.
Also tried 'category.name' ,but it's displaying same values, and 'category_id' is displaying label correctly, but the name - according to id's.
How should I solve that?
Are you define relation for category, like this?
public function getCategory()
{
return $this->hasOne(Category::className(),['id'=>'category_id']);
}
If you want to display in GridView, you can do it like you
[
'attribute' => 'category_id',
'value' => 'category.name',
],
If you want to display in DetailView, you can do it like this
[
'attribute' => 'category_id',
'value' => $model->category ? $model->category->name : '',
],
seems you need a label.
the simplest way is add the label direcly in the detail view item
[
'label' => 'Category',
'attribute' => 'category_id',
'value' => ....,
],
If I'm doing 'label' => false, it is still showing the empty cell of the label. Is it possible completely not to render label cell somehow? Many thanks!
UPDATE: 'labelColOptions' => ['hidden' => true] works!
You can use visible property :
For example,
[
'attribute' => 'name',
'value' => whatever,
'visible' => (!empty($model->name)),
]
I'd like to insert 2amigos' TinyMCE widget in Kartik's DetailView edit mode. This is what I got by now:
[
'attribute' => 'myAttribute',
'format' => 'raw',
'type' => 'widget',
'widgetOptions' => ['class' => TinyMce::classname()],
'value' => $model->myAttribute,
],
With this chunk I managed to show TinyMCE editor with default settings. What I'm trying to do now is to show it with custom settings defined by:
Yii::$app->params['myTinyMceParams']
In form I'm doing this:
<?= $form->field($model, 'myAttribute')->widget(TinyMce::className(), Yii::$app->params['myTinyMceParams']) ?>
Any ideas?
I finally found a solution, maybe not ideal but fully operative: to merge both 'class' array and rest-of-options array into 'widgetOptions':
'widgetOptions' => ArrayHelper::merge(['class' => TinyMce::classname()], Yii::$app->params['tinyMceParams']),