jeudi 18 novembre 2021

Yii2 checkbox with ajax or pjax in activeform

i have a activeform with field status(column) like checkbox. help me i want to when i pressed it the data will change in database like 0 -> 1 or 1 -> 0. i want use it without submit button, maybe use ajax or pjax but i havenot work with these early.

public function actionView($id)
    {
        $model = $this->findModel($id);
        $taskModel = $model->tasks;

        return $this->render('view', [
            'model' => $model,
            'taskModel' => $taskModel
        ]);
    } 

view.php file


<?php $form = ActiveForm::begin(); ?>

    <div class="panel panel-default">

        <div class="panel-body container-items"><!-- widgetContainer -->
            <?php foreach ($taskModel as $index => $task): ?>
                <div class="item panel panel-default"><!-- widgetBody -->
                    <div class="panel-heading">
                        <span class="panel-title-address">Задача: <?= ($index + 1) ?></span>
                        <div class="clearfix"></div>
                    </div>
                    <div class="panel-body">
                        <?php
                        // necessary for update action.
                        if (!$task->isNewRecord) {
                            echo Html::activeHiddenInput($task, "[{$index}]id");
                        }
                        ?>

                        <div class="row">
                            <div class="col-sm-8 d-flex">
                                <div class="mt-2 mr-2">
                                    <?= $form->field($task, "[{$index}]status")->checkbox() ?>
                                </div>
                                <?= $form->field($task, "[{$index}]zet")->textInput([
                                    'readonly' => true,
                                ])->label(false) ?>
                                <?= $form->field($task, "[{$index}]data_end")->textInput([
                                    'readonly' => true,
                                ])->label(false) ?>
                            </div><!-- end:row -->
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>

    <?php ActiveForm::end()?>

enter image description here




Aucun commentaire:

Enregistrer un commentaire