CJuiDatePicker check messages do not work

Hey.

I have a problem with formal validation in the Yii framework.

Here is my VIEW code :

    <?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(); ?>

Nothing . But validation messages working only for textField (Ajax requests are sent only with textField onChange).

How to enable CJuiDatePicker validation messages?

+5
source share
4 answers

You just need to specify the correct identifier for the CJuidatepicker object , use CHtml::getIdByNameid to create the value, try specifying the html element there, it should be something like

'id' => CHtml::getIdByName(get_class($model) . '[' . $attribute . ']')

it will be something like this:

  $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'
    ),
  ));
+3
source

Wond Answer " " ...

, :

Yii CActiveForm

views/site/login.php :

$form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
    'validateOnSubmit'=>true,
),

, :

$form=$this->beginWidget('CActiveForm', array(
'id'=>'login-form',
'enableAjaxValidation' => true,
'clientOptions' => array(
        'validateOnSubmit' => true,
        'validateOnChange' => true,
),

: http://sky-walker.net/temp/test/yii/testdate/index.php?r=site/login

+1

This is what I did and it works, I think you should enable value

<?php echo $form->labelEx($model,'reportDate'); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', 
    array( 'model'=>$model,
    'attribute'=>'reportDate',
    **'value'=>$model->reportDate,**
     'options'=>array(
     'showButtonPanel'=>true,
     'changeYear'=>true,
     'changeMonth'=>true,
      'autoSize'=>true,
     'dateFormat'=>'yy-mm-dd',
     'defaultDate'=>$model->reportDate,
     ),
    ));
    ?>
<?php echo $form->error($model,'reportDate'); ?>
0
source

this problem can simply be clicked by adding $form->error($model,'end_date')after CJuiDatePicker .

$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'
    ),
  ));
 echo $form->error($model,'dateTo');// added to enaple clint validation
0
source

All Articles