Yii: CActiveForm JUI – JQuery UI Inputs (CJuiDatePicker)

I found it pretty difficult to find a reference for how to integrate a jQuery UI date picker in with my CActiveForm view and model.

This is what I found to work correctly for datepicker, for the model field “dob_date”.

<div>
<?php echo $form->labelEx($model, 'dob_date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
   'name' => CHtml::activeName($model, 'dob_date'),
   'value' => $model->attributes['dob_date'],
));
?>
<?php echo $form->error($model, 'dob_date'); ?>
</div>

You might need to wrap a function around $model->attributes['dob_date'] to output it as dd/mm/YYYY from a timestamp if that’s the type of field the model attribute represents

Published on Wednesday, January 19th, 2011, at 15:54, and filed under Javascript, jQuery, PHP, Web Development, Yii.

Share: Digg it!Save on del.icio.usMake a trackback.

Previous Post: .

Next Post: .

2 Responses

  1. Stmpy Says:

    Here is an example of one I did just barely … and it works well

    labelEx($model,’birthDate’,array(‘label’=>$label)); ?>
    widget(‘zii.widgets.jui.CJuiDatePicker’,array(
    ‘model’=>$model,
    ‘attribute’=>’birthDate’,
    // additional javascript options for the date picker plugin
    ‘options’=>array(
    ‘showAnim’=>’fold’,
    ‘dateFormat’=>’yy-mm-dd’,
    ‘changeYear’=>true,
    ‘changeMonth’=>true,
    ‘yearRange’=>’1940:2011′
    ),
    )); ?>
    error($model,’birthDate’); ?>

  2. Meg Says:

    thanks a million! that was very helpfull (especially since the yiiframework website is down at the moment)

    Meg

Leave a Reply