Skip to content

How to add Date Picker to a Form Text Field in YII?

Last updated on February 10, 2018

Here is simple code snippet for adding date picker in YII. We have a Date Picker widget in Yii so I am gonna show you how to use this widget with simple blow code sample.

labelEx($model,'deadline'); 
	 $this->widget('zii.widgets.jui.CJuiDatePicker', array(
		'model'=>$model,
		'attribute'=>'deadline',
                 'value'=>$model->deadline,
		//additional javascript options for the date picker plugin
		'options'=>array(
			'dateFormat'=>'yy-mm-dd',
			'showAnim'=>'fold',
                        'debug'=>true,
			'datepickerOptions'=>array('changeMonth'=>true, 'changeYear'=>true),
		),
		'htmlOptions'=>array('style'=>'height:20px;'),
	 ));
	
echo $form->error($model,'deadline'); 
?>

For more options visit : http://www.yiiframework.com/doc/api/1.1/CJuiDatePicker

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments