Hi,
I just made a simplest form to try to display model errors at only the tab from where the form was sent.
I used 2 times the same form with 2 differents scenario.
I always sent an empty form (to view validation errors) :
controller :
public function actionCreate()
{
$model=new Foobar(isset($_POST['scenario']) ? $_POST['scenario'] : '');
if(isset($_POST['Foobar']))
{
$model->attributes=$_POST['Foobar'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Model:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('title', 'required','on'=>'insert'),
array('title', 'required','on'=>'update'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, title', 'safe', 'on'=>'search'),
);
View:
<h1>Create Foobar</h1>
<?php $this->widget('CTabView',array(
'tabs'=>array(
'tab1'=>array(
'title'=>'tab1',
'view'=>'_form',
'data'=>array(
'model'=>$model,
),
),
'tab2'=>array(
'title'=>'tab2',
'view'=>'_form2',
'data'=>array(
'model'=>$model,
),
),
))); ?>
form:
<div class="row">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>64)); ?>
<input type="hidden" name="scenario" value="insert">
<?php echo $form->error($model,'title'); ?>
</div>
form2 (the same with an update scenario):
<div class="row">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>64)); ?>
<input type="hidden" name="scenario" value="update">
<?php echo $form->error($model,'title'); ?>
</div>
i get:
[color="#FF0000"]Title cannot be blank.[/color] (@ each tab !)
Do i have to create 2 models (one for each form) or scenarios are enough ? (they seems not enough)