Yii2 kartik detailview hide label - yii2

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)),
]

Related

data-* attributes do not work with Html::a() in Yii 2

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
],
]);
},
]

Yii2 select2 widget selected value does not appear when I click edit

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

How to display values according to it's name in DetailView yii2?

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' => ....,
],

yii2 SluggableBehavior is applied to only emty slug field

I am using SluggableBehavior in such way
public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'name',
'slugAttribute' => 'alias',
],
];
}
It works nice If field 'alias' in form is empty.
How to ignore this behaviors If field alias is not empty on form submitting ?
thanks in advance !
Add 'immutable'=>true in the behavour config.
The behaviour works in such way, that if the slugAttribute is not empty when immutable is on, that attribute will not be changed.
Try something like:
Configure this behavior with specific name:
return [
'slug' => [
'class' => SluggableBehavior::className(),
'attribute' => 'name',
'slugAttribute' => 'alias',
],
];
In controller load attributes from the form (before validation).
Check if alias attribute is empty.
If it is not - detach this behavior ($this->detachBehavior('slug')).
Validate model.

Magento Admin Create and Save HTML to Database With a Form Field

I am working on a module that requires some html to be entered to be later called upon and become part of a customer facing widget output.
I've created an administrative backend and that is all working properly, however when I enter html into the field that should be storing the data i receive an error.
I dont need the wysiwyg but I would like to be able to enter html into this value.
At this point I've not done anything special when adding the field to the fieldset. What am I missing?
$contentField = $fieldset->addField('inner_html', 'editor', array(
'name' => 'inner_html',
'style' => 'height:36em;width:36em',
'required' => false,
));
Try
$fieldset->addField('inner_html', 'editor', array(
'name' => 'inner_html',
'label' => Mage::helper('tag')->__('Description'),
'title' => Mage::helper('tag')->__('Description'),
'style' => 'width:700px; height:350px;',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(array('add_variables' => false, 'add_widgets' => false,'files_browser_window_url'=>$this->getBaseUrl().'admin/cms_wysiwyg_images/index/')),
'wysiwyg' => true,
'required' => false,
));