CGridView and validation errors

Hello everyone,

I have a gridview with date column (using CJuiDatepicker), it’s works perfect, but i want validate the input date, because the database don’t recognice some dates like “2011-10-”, or “2011-11”. I have to force the user to select a date from datepicker.

I make a rule in rules() method, and it works because it not make the query, but, it does not show me the errors like "Date is invalid".

How can i show validation errors in CGridview?

Thanks,

Can you get the validation errors to work without the CJuiDatePicker? Are you providing a message for each custom validation rule?

For example…





public function rules()

	{

		return array(

			...

			array('thedate', 'length', 'max'=>12,), // <- message not necessary here, default is good

			array('thedate', 'type', 'type' => 'date', 'message' => '{attribute}: is not a date!', 'dateFormat' => 'yyyy-MM-dd'),

			...

		);

	}




Also, be sure you are displaying the errors in your form, if there are any.

Thanks for asking me eholsinger!

You have right, the errors message don’t appers in any inputs, this is my rules




	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

             		array('dateextrac, dateproc', 'required'),

			array('dateextrac', 'length', 'max'=>12),

                        // I comment this.

                        //array('dateextrac, dateproc', 'safe', 'on'=>'search'),




The messages i don’t know how to show them, because i have to include them joined with the input, below it.

But, i think the input has to colored red automatic, or not?

Typically you would put something like this in your form view




<?php echo $form->errorSummary($model); ?>


...


<?php echo $form->labelEx($model,'dateextrac'); ?>

<?php $form->widget('zii.widgets.jui.CJuiDatePicker', array(

	'model'=>$model,

        'attribute'=>'dateextrac',

        'value'=>$model->dateextrac,

         // additional javascript options for the date picker plugin

         'options'=>array(

                   'showAnim'=>'fold',

                   'dateFormat'=>"yy-mm-dd",

                   'defaultDate'=>$model->dateextrac,

         ),

         'htmlOptions'=>array(

                   'style'=>'height:20px;'

         ),

      ));

?>

<?php echo $form->error($model,'dateextrac'); ?>



The first summary would just tell the user there were errors, while the $form->error($model, ‘dateextrac’) displays the error for the date field.