Yii Framework Forum: CGridView and validation errors - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView and validation errors Rate Topic: -----

#1 User is offline   declan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-December 10

Posted 25 October 2011 - 03:13 PM

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,
0

#2 User is offline   eholsinger 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 12-May 09
  • Location:Maine, USA

Posted 26 October 2011 - 08:54 AM

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.
0

#3 User is offline   declan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 10-December 10

Posted 26 October 2011 - 10:26 AM

View Posteholsinger, on 26 October 2011 - 08:54 AM, said:

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?
0

#4 User is offline   eholsinger 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 12-May 09
  • Location:Maine, USA

Posted 26 October 2011 - 02:11 PM

View Postdeclan, on 26 October 2011 - 10:26 AM, said:


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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users