PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

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

 February 01, 2022     jquery, widget, yii     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing