Siva Kumar
Siva Kumar

Reputation: 772

Yii CJuiDatePicker is not working when page loaded with ajax but works with direct url access

It is little confusing the working of CJuiDatePicker widget. when i accessing page with direct URL it working fine and calender displayed as required but the problem is that when i load the page into a dynamic portion with ajax call,Only text-fields are appearing but calender is not displaying after clicking on it.

$this->renderPartial('index', array('policyModel' => $policyModel, 'roomModel' => $roomModel, 'formModel' => $formModel,'response' => $response),false,true);

Widget Code

 $this->widget('zii.widgets.jui.CJuiDatePicker', array(
   'name' => 'start_date',
    'options' => array(
        'dateFormat' => 'yy-mm-dd',
        'showAnim' => 'fadeIn', 
        'changeMonth' => true,
        'changeYear' => true,
        'yearRange' => '2000:2099',
        'minDate' => '+1d',
        'maxDate' => '10Y',
    ),
    'htmlOptions' => array(
        'readonly' => 'readonly',
        'size' => 7,
    ),
));

Can any one please help me ,I am posting the question after so many hours of search.

Upvotes: 0

Views: 1027

Answers (2)

rdgronckel
rdgronckel

Reputation: 26

You have to set a unique ID for the datepicker. I do so with the php-function uniqid()

$this->widget('zii.widgets.jui.CJuiDatePicker', array(
   'id' => 'start_date'.uniqid(),
   'name' => 'start_date',
    'options' => array(
        'dateFormat' => 'yy-mm-dd',
        'showAnim' => 'fadeIn', 
        'changeMonth' => true,
        'changeYear' => true,
        'yearRange' => '2000:2099',
        'minDate' => '+1d',
        'maxDate' => '10Y',
    ),
    'htmlOptions' => array(
        'readonly' => 'readonly',
        'size' => 7,
    ),
));

Good luck!

Upvotes: 1

overals
overals

Reputation: 92

You need re-init datepicker after ajax update.After Ajax done, you'll need to add the following line:

$('#start_date').datepicker(); //with your options

Upvotes: 0

Related Questions