toMeloos
(Tom)
January 31, 2010, 3:28pm
1
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?
swafsarl
(Info)
February 25, 2010, 1:58pm
3
$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);?>
MaxLord
(Yiiframeworkcom)
May 3, 2012, 4:09pm
4
swafsarl:
$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:
beebe
(Brendon Beebe)
May 3, 2012, 5:29pm
5
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(); ?>
dcolley
(Derek)
October 8, 2012, 3:18pm
6
nishathul
(Nishathul)
July 8, 2013, 10:39am
7
'dob'=>array(
'type'=>'zii.widgets.jui.CJuiDatePicker',
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
),