Jump to content
Larry Ullman's Book Forums

Can'T Get The Validation Messages To Show On Render Partials :(


talofo
 Share

Recommended Posts

Not matter what we do, we can't get the validation messages to appear inside those ajax loaded render partials views:

 

When we submit or if we tab navigate the form fields, the _form does display the messages while the _member don't show nothing.

 

I will try to resume the relevant code here:

 

TEAM Controller

public function actionMember($index){
$model = new TeamMember();
if (Yii::app()->request->isAjaxRequest)
{
$this->renderPartial('_member',array(
'model'=> $model, 'index'=> $index
)); 
} 
}

MEMBER Model

return array(
array('team_id, name, birthdate, email, phone', 'required'),

_member partial

<div class="row-member<?php echo $index; ?>">
<h3>Member <?php if ($index+1==1){echo $index+1 . '(captain)';} else echo $index+1; ?></h3>
<?php echo CHtml::activeLabel($model, "[$index]name",array('class'=>'member')); ?>
<?php echo CHtml::activeTextField($model, "[$index]name",array('class'=>'member')); ?>

</div> ...

_form partial

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'team-form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,

),
'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>
<fieldset>
<section id="members"></section>
<?php echo CHtml::button('Add Member', array('class'=>'addMember'));?>
</fieldset>
<script>
 $('.addMember').click(function(){

$.ajax({
success: function(html){
$('#members').append(html);
},
type: 'get',
url: '<?php echo $this->createUrl('member'); ?>',
data: {index:$('#members div').size()},
cache: false,
dataType: 'html'
</script>

We have tried with outputProcess set to true, and change renderPartial() to render()... an other trickery stuff...

 

No dice.

 

 

Any clue ? :(

 

 

 

 

Link to comment
Share on other sites

If you wish to use rules(), for validating a form that has fields for more then one model and, one of those models (the n on a 1-N relation), needs to be inserted more then once, you have not the possibility to do it with Yii, unless, you get "hacky". :)

 

It seems Yii doesn't call the javascript responsible for the N models each time they are rendered, no matter if you do it trough ajax or without it.

 

A component (extended) to activate the errors was necessary and a trickery on performAjaxValidation method was also necessary to make this work.

 

Otherwise, no dice.

 

If someone actually comes to a similar issue, I'm totally ok for providing the code. I just don't paste it here, because it's a lot of code that will pollute more that it helps now.

Link to comment
Share on other sites

 Share

×
×
  • Create New...