user1648180
user1648180

Reputation: 53

CJuiDatePicker validation messages isn't working

Hi.

I have a problem with form-validation in 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 special. But validation messages working only for textField (Ajax requests are sending only with onChange textField).

How to enable CJuiDatePicker validation messages?

Upvotes: 5

Views: 1982

Answers (4)

Hossein Shahdoost
Hossein Shahdoost

Reputation: 1742

You just have to give the right id to your CJuidatepicker object, use CHtml::getIdByName to create the id value, try to the name of the html element there, it must be something like

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

it would become 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'
    ),
  ));

Upvotes: 3

Osama Jetawe
Osama Jetawe

Reputation: 2705

this problem can be shoved simply 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

Upvotes: 0

Luke Wenke
Luke Wenke

Reputation: 1138

wonde's answer "you should include a value" didn't work for me...

This is what worked:

Yii CActiveForm date validation

views/site/login.php originally had:

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

Things worked when this was changed to:

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

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

Upvotes: 1

wonde
wonde

Reputation: 1181

This is what i did and it works, i think you should include a 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'); ?>

Upvotes: 0

Related Questions