0

I have this raw in my view.php file:

[
              'attribute' => 'Descrizione',
                'format' => 'html',
                'value' => function ( $model ) {
                return nl2br($model->Descrizione);
              },
              'label' => 'Descrizione',
                ],

What I want is to hide the entire field if the value don't contains any character, so if is = "" OR is NULL. So I want to hide the entire field "Descrizione". Which is the option that I have to add in this code? Thank you very much

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

2 Answers2

2

You can use the options attribute to set a CSS style. for example:

empty($model->Descrizione)?'hidden':'' 

https://www.yiiframework.com/doc/api/2.0/yii-widgets-activefield

Eg:

<?= $form->field($model, 'Descrizione',['options'=>['class'=>empty($model->Descrizione)?'hidden':'']])->textInput(['maxlength' => true, 'disabled' => true]) ?>  

Make sure the class "hidden" is actually defined - if you are using bootstrap you can use d-none

nicky
  • 787
  • 2
  • 12
  • 27
0

Are you using Gridview or DetailView ?

If DetailView, try :

[
  'attribute' => 'Descrizione',
  'label' => 'Descrizione',
  'visible' => !empty($model->Descrizione),
  'format' => 'ntext',
],