Using Zii CJuiDatePicker in a CForm

I’m trying to build my first form using the Yii 1.1 CForm form builder. I’d like to include a ‘Date of birth’ field, using a JQuery-based date picker. Found an example on this forum that uses the Zii date picker and took the liberty to copy it. Unfortunately this doesn’t display a dateOfBirth field at all.

The ‘elements’ part of my form definition array includes:


		'dateOfBirth'=>array(

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

		),

So how should I implement it to get this to work?

.




$form = new CForm(

        array(

        'showErrorSummary'=>true,

        'elements'=>array(

        'name'=>array('type'=>'text','maxlength'=>50,),

        'last_name'=>array('type'=>'text','maxlength'=>50,),


        '<div class="row field_birth_date">BirthDate</label>'.

        $this->renderPartial('_genericWidget',array('widName'=>'zii.widgets.jui.CJuiDatePicker','widData'=>array(

        'name'=>'birth_date','model'=>$this->signUpForm,

        'options'=>array('showAnim'=>'fold',),

        'htmlOptions'=>array('class'=>'formInput'),

        )),true).'</div>',


        'email'=>array('type'=>'text','maxlength'=>50,),

        'id_parrain'=>array('type'=>'text','maxlength'=>50,),

        'default_currency'=>array('type'=>'dropdownlist','items'=>Currency::model()->list,),

        'default_language'=>array('type'=>'dropdownlist','items'=>Language::model()->list,),

        'fax'=>array('type'=>'text','maxlength'=>10,),

        ),

        'buttons'=>array('signUp'=>array('type'=>'button','label'=>'Sign up',

'attributes'=>array('onclick'=>$this->renderSignUpAction())))

        ),$this->signUpForm);






The _genericWidget files contains the following code


<?PHP $this->widget($widName, $widData);?>

don’t work in a CForm.


CForm and its behaviors do not have a method or closure named "renderPartial"

screenshots:

One way to do it:




<?php

$form = $this->beginWidget('CActiveForm', array(

    'enableAjaxValidation'=>true,

    'enableClientValidation'=>true,

)); ?>

<?php

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

                'model'=>$model,

                'attribute'=>'dob',

                // additional javascript options for the date picker plugin

                'options'=>array(

                    'showAnim'=>'fold',

                    'showButtonPanel'=>true,

                    'autoSize'=>false,

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

                )

            ));

            ?>


<?php $this->endWidget(); ?>




http://www.yiiframework.com/forum/index.php/topic/22103-cforminputelement-and-cjuidatepicker-config/ seems to have solved this.




	'dob'=>array(

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

				           'options'=>array(


						  	'showAnim'=>'fold',

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

				      	),

				),