1

Is there any way to render partial view which contains a part of form that it's main part is in another view file with AJAX?

I exactly mean one form variable:

`<?php $form = ActiveForm::begin(['enableAjaxValidation' => true,]); ?>`

For Example :

Controller

public function actionOlddetform()
    {
        return $this->renderAjax('_olddet');
    }

View

<?php $form = ActiveForm::begin(['enableAjaxValidation' => true,]); ?>

<?= $form->field($model, 'date')->input() ?>
<?= $form->field($model, 'annotations')->textarea(['rows' => 3]) ?>

<div id="details-form"></div>

<?php ActiveForm::end(); ?>

Part of form included with AJAX for details-form container depends on date value. I know how to check date and show any content of that partial view but when I want to include a part of form I get an error:

PHP Notice 'yii\base\ErrorException' with message 'Undefined variable: form' 
4

1 回答 1

0

似乎您忘记将其实际传递model到您的视图中:

public function actionOlddetform()
{
    return $this->renderAjax('_olddet', ['model' => $dataModel]);
}

如果你想从你的主视图渲染“子视图”,你也需要在那里传递变量(即使我没有在你的视图中看到渲染调用):

<?= $this->render('_formPart', ['form' => $form, 'model' => $model]) ?>
于 2015-05-20T05:54:21.593 回答