Search code examples
phpajaxyiidatepickerrenderpartial

yii datepicker renderpartial ajax - 4th param to true but not working


Wenn i'm loading the view via ajax the datepicker wont work. I already set every single .js and .css file via setclientscript to false on ajaxRequest.

  Yii::app()->clientScript->scriptMap['jquery.js'] = false;
  and the other files as well....

Wenn i check the source code the datepicker input fields are registered

/*<![CDATA[*/
 jQuery(function($) {
jQuery('#date_from').datepicker({'showAnim':'fold'});
jQuery('#date_to').datepicker({'showAnim':'fold'});
...

I also set the renderPartial 4th param to true

  $this->renderPartial('my_view', array(some variables...), false, true);

I also gave evry datepicker on the page a unique ID. That helped neither.

When i reload the page everythign works fine, but via ajaxRequest the datepicker doesnt appear... thats pretty strange

SOLUTION EDIT:

i put at the end of my view the following code:

EDIT: GOT THE SOLUTION:

i put at the bottom of my view:

$("#my_datepicker").removeClass("hasDatepicker");
$("#my_datepicker").datepicker("destroy");
$("#my_datepicker").datepicker();

Solution

  • Adding as answer to accept

    After Ajax request reinitialize your datepicker simply by recalling it once more:

    $("#my_datepicker").datepicker("destroy");
    $("#my_datepicker").datepicker();