【发布时间】:2012-08-29 21:07:00
【问题描述】:
嗨。
我在 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 验证消息?
【问题讨论】:
-
TBH 我不认为那些基于 JQueryUI 的小部件支持客户端验证。在任何情况下我都没有遇到过。它们基本上只是 JUI javascript 的包装器。您或许可以在日期小部件的选项中添加“onSelect”函数并实现您自己的 javascript 验证?
-
是的,这就是我所害怕的。 =(
标签: ajax jquery-ui validation yii