L
L
Lev K2016-04-07 21:16:29
Yii
Lev K, 2016-04-07 21:16:29

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(); ?>

And another question, is it possible to open pjax inside a form? those. use multiple pjax in one form? If it's possible, then I'll just enclose the required fields in pjax and that's it. I tried it, it doesn’t save it in the model, mb did something wrong ...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question