A
A
Alexey Lushnikov2014-02-26 08:53:36
JavaScript
Alexey Lushnikov, 2014-02-26 08:53:36

Why is Yii not generating javascript code for CActiveForm when sorting/paginating CListView?

There is a CListView whose elements are CActiveForm forms.

CListView:

$this->widget('zii.widgets.CListView', array(
            'dataProvider' => $dataProvider,
            'itemView' => '_view',
            'afterAjaxUpdate' => 'someJsFunction'
        ));

_view.php:
$form = $this->beginWidget('CActiveForm', array(
        'action' => array('update', 'id' => $model->productID),
        'id' => 'product-form-' . $model->productID,
        'enableAjaxValidation' => true,
        'clientOptions' => array(
            'validateOnType' => true,
            'validateOnChange' => true,
            'validationDelay' => 500
        ),
    ));
..... 
$this->endWidget();


When loading the first page for each CActiveForm, a js code is generated that allows you to perform ajax requests and save form data. But when paginating / sorting CListView, no code is generated for new loaded js forms, so new forms are not saved. Pagination/sorting is also done using ajax.

What is the right way to generate js code for loaded forms after pagination/sorting of CListView?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dialog, 2014-02-26
@allush

You either need to specify a callback in afterAjaxUpdate, where all binds will be hung up. Or use the so-called jQuery live binding.
This is due to the fact that when pagination is given content without js scripts inside, you can of course fool around in this direction, but for me personally, the path with binding turned out to be much easier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question