L
L
Lev K2016-04-11 12:23:08
Yii
Lev K, 2016-04-11 12:23:08

Yii2 form without updating via Pjax?

Hello.
Is it possible in yii2 to make a form in which the elements will be changed dynamically by pjax, but so that the rest of the form fields are not updated? And if not, how should it be done? JS?
For example, here is the code

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

    <?= $form->field($model, 'id_tc')->dropDownList($car) ?>

    <?  
        $param = ['prompt' => 'Выберите прицеп'];
        echo $form->field($model, 'id_trailer')->dropDownList($trailer,$param);      
    ?>

    <?= $form->field($model, 'Distance')->textInput() ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Создать' : 'Изменить', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

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

Here, after clicking on the button, the entire form is updated, how to make sure that the entered data is not updated?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-04-11
@qonand

it's better not to confuse dynamic form changes with sending it to the server - after all, each call to the server is a load on it. For dynamic change it is better to use JS.
If you still decide to use Pjax for this purpose, just load the data from the post into the model
if (Yii::$app->request->isPost){
$model->load(Yii::$app->request->post())
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question