Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 895
user1648180 Avatar asked Oct 06 '22 17:10

user1648180


2 Answers

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'
    ),
  ));
like image 114
Hossein Shahdoost Avatar answered Oct 10 '22 04:10

Hossein Shahdoost


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

like image 41
Luke Wenke Avatar answered Oct 10 '22 04:10

Luke Wenke