loper_kesasar, on 16 November 2011 - 06:15 AM, said:
baru nyadar,,kok ane g bisa masuk ya tanggalnya
kodingannya kayak gini
<code>
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
//'attribute'=>'dob',
'model'=>$model,
'name'=>'ChildData[dob]',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
'altField' => '#ChildData_dob',
'altFormat' => 'dd-mm-yy',
'yearRange'=>'-18',
'changeYear'=>true,
'changeMonth'=>true,
),</code>
kenapa kalau di var_dump dobnya formatnya dd-mm-yy?caranya biar pas di save balik ke yy-mm-dd gimana ya?
mungkin seperti ini gan
<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
array(
// you must specify name or model/attribute
'model'=>$model,
'attribute'=>'birth_date',
'value' => $model->birth_date,
'options' => array(
'dateFormat'=>'yy-mm-dd',
'altFormat'=>'dd-mm-yy',
'altField' => '#Person_birth_date',
'showOn'=>'button',
//'buttonImage'=>Yii::app()->request->baseUrl.'/images/technorati2.png',
//'buttonImageOnly'=> true,
'changeMonth' => 'true',
'changeYear' => 'true',
'yearRange'=>'-90',
//'showButtonPanel' => 'true',
'constrainInput' => 'false',
'duration'=>'fast',
'showAnim' =>'slide',
),
)
); ?>
keterangan
'altField' => '#Person_birth_date',
coba perhatikan ini gan ..!
'model'=>$model,
'attribute'=>'birth_date',
karena model saya adalah Person, kemudian atributnya birth_date maka penulisan untuk 'altField' adalah #Person_birth_date bukan #Person[birth_date], untuk lebih jelas dapat di cek menggunakan Firebug..!
kemudian agar dapat disimpan tambahkan kode ini di
Model
protected function beforeSave()
{
if(parent::beforeSave())
{
// input => 99-99-9999
// simpan => 9999-99-99
$this->birth_date=substr($this->birth_date,6,4).'-'.substr($this->birth_date,3,2).'-'.substr($this->birth_date,0,2);
return true;
}
else
return false;
}
semoga membantu