你好.
我在Yii框架中遇到表单验证问题.
这是我的VIEW代码:
<?PHP $form = $this->beginWidget('CActiveForm',array( 'id' => 'search-form','enableAjaxValidation' => true,'enableClientValidation' => true,'focus' => array($model,'ccc'),'clientOptions' => array( 'validateOnSubmit' => true,),)); ?> <?PHP echo $form->errorSummary($model); ?> <div class="row"> <?PHP echo $form->labelEx($model,'input'); ?> <?PHP echo $form->textField($model,'input',array('class' => 'input-medium','maxlength' => 11,)); ?> <?PHP echo $form->error($model,'input'); ?> </div> <div class="row"> <?PHP echo $form->labelEx($model,'date'); ?> <?PHP $this->widget('zii.widgets.jui.CJuiDatePicker',array( 'attribute' => 'date','name' => 'date','model' => $model,'language' => 'ru','options' => array( 'dateFormat' => 'dd/mm/y','showAnim' => 'slideDown','changeMonth' => true,'changeYear' => true,'showOn' => 'button','constrainInput' => 'true','htmlOptions' => array( 'style' => 'height:15px; width:6em' ),)); ?> <?PHP echo $form->error($model,'date'); ?> </div> <?PHP $this->endWidget(); ?>
没什么特别的.但验证消息仅适用于textField(Ajax请求仅使用onChange textField发送).
如何启用CJuiDatePicker验证消息?
解决方法
你只需要给你的CJuidatepicker对象提供正确的id,使用CHtml :: getIdByName创建id值,尝试在那里的html元素的名称,它必须是类似的东西
'id' => CHtml::getIdByName(get_class($model) . '[' . $attribute . ']')
它会变成这样:
$this->widget('zii.widgets.jui.CJuiDatePicker',array( 'id' => CHtml::getIdByName(get_class($model) . '[date]'),'attribute' => 'date','options' => array( 'dateFormat' => 'dd/mm/y',));