Add Datepicker In Cform

Hi, All,

I want to add a datepicker (like CJuiDatePicker) into one element in CForm.




public function getForm() {

	$return=new CForm(array(

		'showErrorSummary'=>true,

			'elements'=>array(

				'networkDate'=>array(	

					'type'=>'text',

					'hint'=>'Date for network',

					'attributes'=>array(

						'class'=>'hasDatepicker',

					),

				),

				"<script type=\"text/javascript\">

				/*<![CDATA[*/

				jQuery(function($) {

					jQuery('#NetworkDetails_networkDate').datepicker({'changeYear':true,'dateFormat':'mm/dd/yy'});

				}

				/*]]>*/

				</script>",

...



My code is not working. I must be missing something but I don’t know.

Is anyone has same issue, and I want to know how you solve the issue.

Thanks,

Johnny

Why not use CActiveForm ?

http://www.yiiframework.com/doc/api/1.1/CActiveForm

I don’t use often CForm but I think CActiveForm is more flexible

Thank you KonApaz,

I am design a form in one wizard step. So each wizard step is one class under Model, and in that class it calls getForm function, which return CForm to build the wizard page. Because each wizard step is one CFormModel. I don’t know how to change that. I am using WizardBehavior, I don’t know what is best way to handle that.

I designed another CActiveForm, but I don’t know how to insert it into wizard pages. Do you have any suggestions in this case?

Thank you for your time,

Johnny

Ok,

check something like that


'elements'=>array(

...

...

 'datepicker'=>array(

    'type'=>'zii.widgets.jui.CJuiDatePicker',

   ),

...

...

Thank you KonApaz, you solution is correct.

It makes CForm very easier to use any widgets.




				'networkStartdatePlan'=>array(

					'type'=>'zii.widgets.jui.CJuiDatePicker',  //this is widgets name

					'hint'=>'Initial status for the network',

					'attributes'=>array(  //put widgets options here

						'options'=>array(

							'changeYear'=>true,

						),

					),					

				),



Very nice!

The type property can also be a class name or a path alias to the class. In this case, the input is generated using a widget of the specified class. Note, the widget must have a property called "model" which expects a model object, and a property called "attribute" which expects the name of a model attribute.

May not clear in above note, here is extend information.

Besides these built-in types, the type option can also take a widget class name or the path alias to it. The widget class must extend from CInputWidget or CJuiInputWidget. When rendering the input element, an instance of the specified widget class will be created and rendered. The widget will be configured using the specification as given for the input element.

thanks… :)