Answer the question
In order to leave comments, you need to log in
How to return an ActiveForm from an anonymous function in YII2?
When rendering the GridView, it is necessary to display an "update" button along with a modal window with an ajax edit form.
To display the column I use the following code:
[
'class' => yii\grid\ActionColumn::className(),
'template' => '{view} {update} {delete}',
'buttons' => [
'update' => function ($url, $model, $key) {
$html = [];
$html[] = Modal::begin([
'toggleButton' => ['label' => 'update', 'class' => 'btn btn-primary'],
]);
$html[] = $form = ActiveForm::begin([
'options' => [
'data-pjax' => true,
],
]);
$html[] = $form->field($model, 'id')->textInput();
// всякие поля формы
$html[] = ActiveForm::end();
$html[] = Modal::end();
return implode("\n", $html);
}
]
Answer the question
In order to leave comments, you need to log in
I use ob_start()...etc.
A simple implementation, but a little bit unreadable, so I cover such comment blocks.
ActiveForm and Modal are descendants of Widget, which has a render() method that returns html, I would dig in this direction
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question