default value for Cjuidatetimepicker


(Richa) #1

Hi all,

I am using CJuiDateTimePicker in my code. I want to keep a default value. Can anybody tell me how to do this?

my code is:





<?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');

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

        'model'=>$model, //Model object

	

        'attribute'=>'['.$i.']timein', //attribute name


                'mode'=>'time', //use "time","date" or "datetime" (default)

'value'=>'08:00:00'////////////// this does not work

        'options'=>array() // jquery plugin options

    ));

?>



Thanks in advance


(Codesutras) #2

You should spend some time Here

Hope this will definitely help you.And please define a default formate in option array and then ty to assign a default value.Might be this will work for you.


(Richa) #3

hey jayant,

thanks for the quick reply…

Your suggestion helped but not fully. I can set defalut value by using the parameter hour, it reflects on the slider but i want the value to be shown in the text box. Is this possible?

Thanks again


(Codesutras) #4

would you please show me your current code snippet.so that i can figure out what the prob here…


(Richa) #5

hey jayant,

here is my code


<?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');

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

        'model'=>$model, //Model object

	

        'attribute'=>'['.$i.']timein', //attribute name


                'mode'=>'time', //use "time","date" or "datetime" (default)

        'options'=>array('timeFormat'=>'hh:mm:ss','hour'=>'8'


) // jquery plugin options

    ));

?>

As u can see i have set the hour to 8 which shows on the slider but it doesnt display in the text field. I need the time to be displayed in the text field without first selecting the time.


(Codesutras) #6

Well try this and let me know




<?php Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');

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

        'name'=>'define a model attribute here', // like Event[start_date]

        'model'=>$model,

        'value'=>"define a value here",

	 //  'attribute'=>'['.$i.']timein', //attribute name


                'mode'=>'time', //use "time","date" or "datetime" (default)

        'options'=>array('timeFormat'=>'hh:mm:ss','hour'=>'8'


) // jquery plugin options

    ));

?>




might be this will work.


(Iwan Susanto) #7

Hey jayant,

Thanks for your support


(Csibug) #8

hi all,

i have some problem regarding the CJuiDateTimePicker extension.

i would like to update an existing record. on the form, the textbox is filled with the current value of the model attribute: 2012-03-29 12:25:00

if i click on the textbox, the CJuiDateTimePicker opens, but not with the proper datetime. only the time part is correct, the selected date is the current (2012-04-24), not the proper value of the record (2012-03-29).

Here is the fragment of my view:

<?php Yii::import(‘application.extensions.CJuiDateTimePicker.CJuiDateTimePicker’);

	    &#036;this-&gt;widget('CJuiDateTimePicker',array(


	        'model'=&gt;&#036;model, //Model object


	        'attribute'=&gt;'begin_date', //attribute name


	        'mode'=&gt;'datetime', //use &quot;time&quot;,&quot;date&quot; or &quot;datetime&quot; (default)


	        'options'=&gt;array('dateFormat'=&gt;'yy-mm-dd', 'timeFormat'=&gt;'hh:mm:ss') // jquery plugin options


	    ));


	?&gt;

(Yiiframework) #9

Same problem - the time part is set correctly, but the month stays on the current month (right now, that’s April 2012), rather than display the date contained in the model (eg May 2008).

Has anyone found a solution to this?


(Tal) #10

I spent half a day trying to figure this out and finally found a solution. The JS files are out of date and have to be updated. I can’t post links as my account is too new (couldn’t post a comment in the extension page either, a very annoying way to prevent spam), so google “yii improving datetimepicker” for the solution at Hollow Developers, or go straight to Trent Richardson’s jQUery-Timepicker-Addon page at Github and download them from there.


(Gianluca Pericoli) #11

A little late but I resolved today the problem.

I must put the value on the field on the update, than before the render I wrote:




		$model->date = date_create($model->date)->format('d/m/Y H:i'); 

		

		$this->render('update',array(

			'model'=>$model,

		));



WHY?

because on the extension class on line 37:




		if($this->hasModel())

			echo CHtml::activeTextField($this->model,$this->attribute,$this->htmlOptions);

		else

			echo CHtml::textField($name,$this->value,$this->htmlOptions);



We have an activeTextField if we pass one model as parameter and I wrote on google: activeTextField change default value and I found this solution.

Sometimes when I feel sick I try to write synthoms on google but normally don’t work very well… Maybe there are better solutions :lol: