CJuiDatePicker and SetDate

Hey.

I’m having some trouble accessing a CJuiDatePicker after it has been initialized with javascript.

All I want to do is use the .datepicker(‘setDate’, ‘11-Jan-12’) to change the date on the calendar.

Here is the code I’ve got that sets up the DatePicker




$this->widget('zii.widgets.jui.CJuiDatePicker', array(

            'name'=>'apptDate',

            'themeUrl' => Yii::app()->theme->baseUrl . '/css/jui',

            'flat'=>true,

            'value'=>date('d-M-y'),

            'htmlOptions'=>array(  

                'id'=>'apptDate',

            ),

            'options'=>array(

                'dateFormat'=>'dd-M-yy',

                'onSelect' => 'js: function(dateText, inst){

                            loadData(dateText);

                        }', 

            )

        ));



Here is the code I’m attempting to use to set the date:




$('#apptDate').datepicker('setDate', '17-Jan-12');



Any insight to why the date on the calendar won’t actually change would be a great help.

C

After hours of searching and messing around I have found a solution… or at least I think this is the solution.

So for anyone that comes across this here is what I have found.

When using CJuiDatePicker without a model/attribute in the setup like I have above, the output from Yii creates a div with the name [name]_container

In my case I get the resulting html code:




<input id="apptDate" name="apptDate" type="hidden" value="17-Jan-12" />

<div id="apptDate_container" name="apptDate_container"></div>



You can see Yii gives me apptDate_container

This must be used when accessing the CJuiDatePicker with javascript.

So I just changed my set date line of code to




$('#apptDate_container').datepicker('setDate', '17-Jan-12');



I wasn’t able to find any documentation on this little caveat during my trudging through forum post after forum post so I hope it helps someone.

This happens when you use flat.


'flat'=>true,



PS: Apologies for replying to an old thread but it could help someone.