A
A
Alexander Stepanov2018-02-15 12:20:06
Yii
Alexander Stepanov, 2018-02-15 12:20:06

Why are checkboxes cleared when clicked?

It is necessary to arrange filtering on the site beautifully.
Filtering itself works, but .. only within native ActiveForm tags.
I do select or checkboxList - everything works wonderfully and multi-select without reloading the page, only the view of this is terrible.
And if I make a layout of a drop-down list with checkboxes in divs, and just checkboxes in a row - the choice occurs only on the last click + the checkbox "resets" the checked checkbox
of the View:

<?php
$this->registerJs(
    '$("document").ready(function(){
        $(document).on("change", "label", function(e) {
        e.preventDefault();
            $("#filter-form").submit();
        });
    });'
);
?>

<div class="shop-new col-md-12 animated bounceInLeft">

<h1>
    New
</h1>

    <div class="col-md-12 filters-menu-section">

    </div>

<?php Pjax::begin([
    'id' => 'productList',
    'enablePushState' => false,
    'enableReplaceState' => false,
]); ?>

    <?php $form = ActiveForm::begin([
        'id' => 'filter-form',
        'action' => ['new'],
        'method' => 'get',
        'options' => ['data-pjax' => true],
    ]); ?>

    <div class="new-sortFilter-nav status_chk">
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>
    </div>
    <?php ActiveForm::end(); ?>

<?= $this->render('_loop', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); ?>

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

</div>

_search.php
<div class="product-search">

    <?php $form = ActiveForm::begin([
        'id' => 'filter-form',
        'action' => 'search',
        'method' => 'get',
    ]); ?>

    <?= $form->field($model, 'category_id')->checkboxList(Category::find()->select(['title', 'id'])->indexBy('id')->column()) ?>

    <?php // echo $form->field($model, 'price') ?>

    <?php // echo $form->field($model, 'new') ?>

    <?php // echo $form->field($model, 'hit') ?>

    <?php // echo $form->field($model, 'sale') ?>

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

</div>

Or at least how, in this situation, can parent categories be distinguished by a separate class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-02-15
@OKyJIucT

Because the data is updated via PJAX, and you do not pass the state of the checkboxes to the model that fills it, so they are reset.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question