Answer the question
In order to leave comments, you need to log in
How to add data-pjax property to field, yii2?
Hello! Need to create a dynamic form in yii2. I looked in the direction of pjax, everything worked out, but now you need to select some fields on the form that will be dynamic, otherwise the whole form is completely updated during dynamics. In my case, 1 dropdownlist should dynamically appear and disappear.
<? Pjax::begin(['enablePushState' => false]); ?>
<?php $form = ActiveForm::begin(['options' => ['data-pjax' => '1']]); ?>
<?= $form->field($modelCouples[0], "[0]id_driver")->dropDownList($driver)?>
<?
if (count($modelCouples) == 2) echo $form->field($modelCouples[1], "[1]id_driver")
->dropDownList($driver);
if ($model->isNewRecord) {
if (count($modelCouples) == 1) echo Html::a('+', ['/trip/create?action=new'],['class' => 'btn btn-primary']);
else echo Html::a('-', ['/trip/create?action=one'],['class' => 'btn btn-primary']);
}
else {
}
?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Создать' : 'Изменить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<? Pjax::end(); ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question