CJuiDatePicker验证消息无效

use*_*180 5 validation ajax jquery-ui yii

你好.

我在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(); ?>
Run Code Online (Sandbox Code Playgroud)

没什么特别的.但验证消息适用于textField(Ajax请求仅使用onChange textField发送).

如何启用CJuiDatePicker验证消息?

Hos*_*ost 3

您只需为CJuidatepicker对象提供正确的 id,用于CHtml::getIdByName创建 id 值,尝试那里的 html 元素的名称,它必须类似于

'id' => CHtml::getIdByName(get_class($model) . '[' . $attribute . ']')
Run Code Online (Sandbox Code Playgroud)

它会变成这样:

  $this->widget('zii.widgets.jui.CJuiDatePicker', array(
    'id' => CHtml::getIdByName(get_class($model) . '[date]'),
    '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'
    ),
  ));
Run Code Online (Sandbox Code Playgroud)