Well, not really. I mean, it will post the result in a array-variable, but it wont link to the model in the "yii way". I still will need to validate the input etc.
I think the way to go is to keep the activeTextField part, put a ‘id=my_date_id’ in the html options, and somehow make the widget datepicker link to this id. I haven’t dug into how I would change the widget to make this work yet, but hopefully I will find this out or someone else can point me to this who has experience with widgets?!
The base class CInputWidget needs the properties “model” and “attribute” to be set, then it will select an activeTextField for you. I assumed I could just set the name (looks the same in the http request), but didn’t check which input field got selected.
I am having the same problem too. When I click submit form button, the value is blank. It didn’t really attach to active model like other textbox which retain value after postback. Is there anyone has solution for this?
Seems like CHtml::activeName(model, attribute) will generate the correct name for you. In my case, I have to take care of an additional data type issue (validation error due to type mismatch).
/Tommy
Note: the properties $model and $attribute was (IIRC) added in an updated CJuiDatePicker, but that was still beyond my knowledge when this post was created.
Hi, I got the ‘jui.EDatePicker’ and using on my one of Form with following setting where a user can select any date by jui.EDatePicker and it save to right table through right Model here is setting…
<div class="row">
<?php echo $form->labelEx($model,'expire_time'); ?>
<?php $this->widget('application.extensions.jui.EDatePicker',
array(
'name'=>'expire_time',
'attribute'=>'expire_time', // Model attribute filed which hold user input
'model'=>$model, // Model name
'language'=>'en',
'mode'=>'imagebutton',
'theme'=>'redmond',
'value'=>date('Y-m-d'),
'htmlOptions'=>array('size'=>15),
'fontSize'=>'0.8em'
)
);?>
<?php echo $form->error($model,'expire_time'); ?>
</div>
I hope it will work with all as mine work like charm
Perhaps rahul.vit09 has a newer version of Yii, so the code provided by Khan didn’t work for him. It happened to me as well. I looked into the Class Reference and found this:
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'publishDate',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
I applied it to my own project and got this working fine:
<div class="row">
<?php echo $form->labelEx($model,'Date Of Birth'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'dateofbirth',
'options'=>array('changeMonth'=>'true', 'changeYear'=>'true'),
'htmlOptions'=>array(''=>'') // None at the moment
));
?>
<?php echo $form->error($model,'dateofbirth'); ?>
</div>
The difference, as you can see, is the path to the class.
Are you trying to save the value selected by datepicker in a different form field, one associated with a model? You should be able to simply assign an ID to the form field and use that as the selector for the ‘altField’ option. I’ve done this with hidden fields that stored the start date of one of my models. It worked like a charm. For example, the code below shows the datepicker widget populating an alternate (target) form field using an alternate format than datepicker’s default.
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'datepicker_field', // Name of the datepicker form field.
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'altField'=>'#some_selector', // The jQuery selector of the "target" field
'altFormat'=>'yy-mm-dd', // If you want the target field to have a different format
),
'htmlOptions'=>array(
'style'=>'height:20px;',
),
));
When the value is selected in the datepicker, it should populate whatever form field has the unique id, ‘some_selector’. For example:
I want to repeat the post once again as posted by member already:
I am having the same problem too. When I click submit form button, the value is blank. It didn’t really attach to active model like other textbox which retain value after postback. Is there anyone has solution for this?