Tuesday, February 1, 2022

[FIXED] Loading Zii widget CjuiDatePicker through AJAX call not working

Issue

Problem summary:
(i) Widget in static portion of form works fine; but
(ii) In dynamically-generated portion, only the text field appears (clicking on it does not create calendar from which to select a date)

Below code shows the 'dynamic' attempt:

(1) A user can click "(+) date":

    <?php echo CHtml::link('(+) Date','javascript:void(0);',array('class'=>'date-add'))?>

(2) A jquery handler does the AJAX request:

    <script>
        $(".date-add").click(function() { $.ajax({
            success: function(html) {$(".date-list").append(html);}, type: 'get',
            url: '<?php echo $this->createUrl('CreateDate')?>',
            data: {index: counter++}, cache: false, dataType: 'html'
        });});
    </script>

(3) The jquery handler triggers actionCreateDate:

    model = new Date;
    $this->renderPartial('_newDate', array(
        'model' => $model,
    ));

(4) And the view code is

    <?php 
        $this->widget('zii.widgets.jui.CJuiDatePicker', array( 
            'name'=>'Date', 'options'=>array(),'htmlOptions'=>array(),
        ));
    ?>

How can I resolve this issue (i.e. have working widgets in dynamically-generated portion of form)? Thanks in advance!


Solution

Your problem is basically on (3), when you do a render partial the js of the render content is not precessed. Hence you could solve this --

model = new Date;
$this->renderPartial('_newDate', array(
    'model' => $model,
));

as --

model = new Date;
$this->renderPartial('_newDate', array(
    'model' => $model,
), false, true);

The forth parameter of the the CController::renderPartial function processes the js of the render content and loads them.



Answered By - Nahian Khondoker

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.