<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'start_time',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'dd/mm/yy',
'defaultDate'=>'3/3/2011', // It's not working
),
'htmlOptions'=>array(
'style'=>'height:20px;',
'value'=>'3/3/2011', // It's not working either
),
)); ?>
but I can’t set the Default date.
The options => defaultDate is kind of working: it sets the date “internally”, so when I click the text field I get the calendar starting on the stated date, but I want it to DISPLAY the default date, so the user knows that something is already set and doesn’t worry the date was lost in the update process.
For this reason I tried setting the "value" in htmlOptions but the parameter is simply ignored. What am I doing wrong?
I am new in yii.I am using CJuiDateTimePicker to pick calender date and time.But when i select date from date and calender date picker and submit it shows "Start Time cannot be blank.".The code is below.My table field name is socstd and using gii crud functionality of yii.
As Lube points out, the defaultDate is being overwritten, so to answer the OP, all you need to do is put ‘value’ in the top level of the properties array, NOT under ‘htmlOptions’ – see below (and note that you ought to use leading zeros since that’s what you specified with dd and mm in dateFormat)
However, technically (IMHO), defaultDate SHOULD NOT have to be overwritten with the value at all, for the reason stated above. Unfortunately, as far as I can tell from the way jQuery’s datepicker is written, an inline instance “incorrectly” (by my reasoning) gets its initial value from defaultDate, whereas it should get it from some other data source, such as the hidden field that CJuiDatePicker produces. The trouble is, attaching datepicker to a field implies (according to jQuery’s logic) that the field is selectable, and a hidden field is obviously not, and of course it also makes the datepicker NOT inline . So maybe datepicker should read the initial value from an HTML5 data-* attribute in the div or span tag. Something to ask the gurus at jQuery.org…
As far as Yii is concerned in the mean time, CJuiDatePicker probably should be refactored to call datepicker(‘setDate’, $(’$id’).val()) via jQuery’s ready function when flat is true.