[Solved] CJuiDatePicker does not work with beforeShowDay option

I am using CJuiDatePicker


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

     'name'=>'day',

      // additional javascript options for the date picker plugin

      'options'=>array(

           'showAnim'=>'fold',

           'minDate' => 0,

           'beforeShowDay' => 'noWeekends'

       ),

       //'htmlOptions'=>array(

        //  'style'=>'height:20px;'

       //),

 ));

And the output is


<script type="text/javascript" src="/new_mst/assets/32ce51a1/jui/js/jquery-ui.min.js"></script>

<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

jQuery('#day').datepicker({'showAnim':'fold','minDate':0,'beforeShowDay':'noWeekends'});

});

/*]]>*/

</script>



The picker does not work with the beforeShowDay option. The error is "x.apply is not a function". I am using Yii 1.1.6. I think it is expecting a function there, not a string.

However, the CJavascript::encode function used to generate the options string has no provision to generate such an output.

The datepicker works in a standalone page. The relevant option, however, does not have quotes around beforeShowDay or noWeekends.


$('#day').datepicker({minDate:0, beforeShowDay:noWeekends});

If you do not want quotes do it this way:







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

     'name'=>'day',

      // additional javascript options for the date picker plugin

      'options'=>array(

           'showAnim'=>'fold',

           'minDate' => 0,

           'beforeShowDay' => 'js:noWeekends' //<---- see the JS at the beginning?

       ),

       //'htmlOptions'=>array(

        //  'style'=>'height:20px;'

       //),

 ));



Thanks Antonio! That worked perfectly.

Further, it should be


'beforeShowDay' => 'js:$.datepicker.noWeekends'

as I found out after ‘js:noWeekends’ gave a ‘function not found’ error.