Is there a simple way to conditionally hide one of the rows on detailview if it met certain conditions?
For example if I’ve got the ff field:
name, has_question, question
if has question is true, then question displays, otherwise it doesn’t show.
Is there a simple way to conditionally hide one of the rows on detailview if it met certain conditions?
For example if I’ve got the ff field:
name, has_question, question
if has question is true, then question displays, otherwise it doesn’t show.
Can you show here how you output rows on detailview?
You can use closure for output with your condition
below is my code. I am actually hoping if there would be an available function to allow a closure
<?= DetailView::widget([
'model' => $productModel,
'attributes' => [
'name',
'has_question:boolean',
'question:ntext',
],
]) ?>
Is there such that would function like this?
[
'attribute' => 'question',
'showif' => $model->has_question == true,
],
You could populate ‘attributes’ array based on conditions.
$attr = [];
$attr[] = 'name';
if($question) $attr[] = 'question';
if($question) $attr[] = 'question';
<?= DetailView::widget([
'model' => $productModel,
'attributes' => $attr,
]) ?>
Wow! I just learned something new. I’ll try it and tell you what happens. Thanks!
Amazing! It’s working. Thanks!
You can use something like this
`<?= DetailView::widget([
‘model’ => $productModel,
‘attributes’ => [
[
‘attribute’=>‘question’,
‘captionOptions’ => [
‘class’ => $productModel->has_question? ‘hide’:’’,
],
‘contentOptions’ => [
‘class’ => $productModel->has_question? ‘hide’:’’,
],
],
]
]) ?>
Use visible
attribute:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'name',
[
'attribute' => 'question',
'visible' => $mode->needToShowQuestion(),
],
])
?>
this worked.thanks alot