errorSummary on partial view

Hi,

I have a partial viev (_search) inside my Index view so I’m able to filter data in the listview.

The ‘IP’ field inside the search form is required for this scenario (‘Log_Index’). If a user try to search the listview and he doesn’t select an IP an error should appear in the error summary of the search form.

the problem is that the error summary never appears.

this is a piece of code from the _search partial view:




<?php $form=$this->beginWidget('CActiveForm', array(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'get',

        'enableAjaxValidation'=>false, 

)); ?>

    <div style="clear:both">

        <p class="note">Fields with <span class="required">*</span> are required.</p>

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

    </div>


.......................

........................



in the controller Index action I have:




$model=new Log('search');

$model->unsetAttributes();  // clear any default values


$user=new User;

$ip=new Usersip('Log_Index');


...............................

..............................


if(isset($_GET['Usersip'])){

   $ip->attributes=$_GET['Usersip'];

   $valid=$ip->validate(array('IP'));

   

   if($valid){

    .......................

   }


}



the above code seem to work well because it check correctly if I set the IP attribute or not.

with firebug i’m able to see that the returned code contain the errorSummary block that advice that IP field should not be null.

How can I display the errorSummary block on the page inside the partial view?

in not sure if i understand your case, but in your config file try add the following under components:




   	'log'=>array(

        	'class'=>'CLogRouter',

        	'routes'=>array(

            	array(

                	'class'=>'CWebLogRoute',

            	),

        	),

    	),



Hi,

the Log you noticed in my code is a custom model and han nothing to do with the log message system.

http://www.yiiframew…rSummary-detail

showErrorSummary property of CForm class might be set false

the problem, I think is that the partial view _Search is rendered with the renderPartial method inside the main view Index and it doesn’t refresh correctly after the submit.

the problem is not of the renderPartial method.

I’ve put the CActiveForm widget inside the main view but the behavior is the same and the errorSummary doesn’t display.

try




CHtml::errorSummary($model);



and see what you get from it

its what CActiveForm actually does internally

also check to see if your $model variable is actually set

I echoed it after




$valid=$ip->validate(array('IP'));



and the result from firebug is:

<div class="errorSummary"><p>Per favore, correggere i seguenti errori di input:</p>

<ul>

<li>Ip non può essere nullo.</li>

</ul></div>

the same div message that I only can see on the page only with firebug.

ok,

I’ve tried with yii but definitely I cannot make it work correctly.

So I switched out to the old jquery validation using the jquery.validate plugin.

this is the js script I used on the index view:




<script type="text/javascript" charset="utf-8">

    $(document).ready(function() {

       $('#searchForm').validate({

           errorElement: "div",

           rules: {

               'Usersip[IP]' : "required"

           },

           messages: {

               'Usersip[IP]' : 'è necessario selezionare un IP'

           },


            submitHandler: function(form) {

               $.fn.yiiListView.update('log-view', {

		data: $(this).serialize()

                });

                return false;

            }

       });

    });

</script>



I wish Merry Christmas to all Yii people.