DateTime Picker with database

Hi all,

 I am trying to use the DataTime widget using jquery . The display is working fine. But when i click he create button its not getting stored in database. It says the textbox is empty. The code i used is 



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

                            'name'=>'service_start_date',

                            'model'=>$model,

                            'attribute'=>'service_start_date',

                            'value'=>$model->service_start_date,

                            // additional javascript options for the date picker plugin

                            'options'=>array(

                                'showAnim'=>'fold',

                               'dateFormat'=>'yy-mm-dd'


                            ),

                            'htmlOptions'=>array(

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

                            ),

                        ));  ?> 



The column name is service_start_date.

When you provide the ‘model’ and ‘attribute’ parameters, it isn’t necessary to set the ‘name’ parameter.

Can you try leaving it out?

Hi krisd,

I just tried by removing the ‘name’ parameter. It still says “Service Start Date cannot be blank”.

Can you post you controller code please?

thanks for the reply krisd.

Actually i used the widget directly in the form. I did not write any code in the controller.

Do this for the name—>




// you must specify name or model/attribute

 'name'=>'ModelName[service_start_date]',




forget model and attribute or use them ‘without the name’ as your name exposed above is wrong. It should work without it… never tried though, I use the above




// DO NOT INCLUDE NAME, your name is wrong must be ModelName[attributename]

'model'=>$model,

'attribute'=>'service_start_date',



Had this kind of problems before. I’ve used the yii debug toolbar extension http://www.yiiframework.com/extension/yiidebugtb/ to check what the form was actually posting because I was trying to assign to the attribute something that wasen’t posted.

With the toolbar you can click yii->request and you’ll see the posted array.

is service_start_date a safe attribute?

Big Thanks to all. The datatime picker is working. I removed name attribute.

Hi,

the time is stored as timestamp (converted in beforeValidate) in the database, which is fine. But for Update purposes I want to show the datetime (which was set before) in the format a custom format: Thought this would be working with the value-attribute, but with this code only the timestamp is shown.




$this->widget('CJuiDateTimePicker',array(

	'model'=>$model, 

	'attribute'=>'endtime', 	

	'value'=> date("d.m.Y H:i",$model->endtime),			

	'mode'=>'datetime', 

	'options'=>array('dateFormat'=>'dd.mm.yy'), 

	'language' => 'de'

));



Any ideas are much appreciated!

Well, quite easy at the end, works with ‘name’ property instead of ‘mode’ and ‘attribute’.


	'name'=>'Spread[endtime]',

	'value'=> date("d.m.Y H:i",$model->endtime),