Hi all,
I am working on a form where I have 2 date fields - opening_date and closing_date.
I have added a validation such that closing_date should be greater than opening_date.
Here is the validation on the server side in model:
public function rules()
{
return array(
//...other fields rules
array('opening_date, closing_date','date','format'=>'yyyy-m-d'),
array('opening_date','compare','compareValue'=>date('Y-m-d'),'operator'=>'>='),
array('closing_date','compare','compareAttribute'=>'opening_date','operator'=>'>')
);
}
And in view:
[html]
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'payment-form',
'enableAjaxValidation'=>false,
'enableClientValidation' => true,
'clientOptions'=> array('validateOnSubmit'=>true),
)); ?>
<!--other fields -->
<div class="row">
<?php echo $form->labelEx($model,'opening_date'); ?>
<?php echo $form->textField($model,'opening_date'); ?>
<?php echo $form->error($model,'opening_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'closing_date'); ?>
<?php echo $form->textField($model,'closing_date'); ?>
<?php echo $form->error($model,'closing_date'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
[/html]
Server side date comparison validation is working properly. But the client side date comparison validation is not working properly. I tested it by removing
'enableClientValidation' => true
.
For eg:
If I enter 2013-03-12 in opening_date field and 2013-03-13 in closing_date field, server side validation validates true, which is correct. But the client side validation validates false. And I get this error: Closing Date must be greater than "2013-03-12".
But if I enter 2014-03-13 in closing_date field, client side validation validates true. ie; it compares year, not date.
What am I doing wrong here?
Please help me to solve the issue.
Thanks in advance,
Greeshma.