RenderPartial and Form Object (AJAX)


I am making a dynamic dropdown inside a form view, that brings a customized view with form elements using renderPartial. Due to the ajax call I can’t use the same $form reference from the parent form view to render the elements. Instead I use pure html to do that.

How can I make this partialview conform with yii form rendering? I want to use the elements and the form->error mechanism so that everything selected on the particular form (it’s a checkbox array) or if the checkbox array is not checked to be showing up in error Summary.

Just in case I can’t do the above, is there a way to append errorSummary (or trigger it client side) so that I could have the error checking?

I am glad I found someone who has the exact same problem !

Anyone has an idea ?

Me too

As I understand, your input fields will be dependent on a dropdown option…

May be too classical but I solve these kind of (simple) problems via model and via view by javascript (forget the renderparial):

In model:


switch (dropdownvalue) {

case x: specialrules = array(aaa);


case y: specialrules = array(bbb);


case z: specialrules = array(ccc);



return array( common rules ) + specialrules;

In view:


$oneOfTheScripts = "blabla"; // blabla script evaluates and shows/hides input elements according to the selected dropdown row. Rules in the model should match the shown elements.


<?php echo $form->dropDownList($formModel, ‘dropdownvalue’, array(‘x’=>‘xxx’, ‘y’=>‘yyy’, ‘z’=>‘zzz’), array(‘encode’=>false, ‘onChange’=>‘javascript:’.$oneOfTheScripts)); ?>

<?php echo other elements ?>

Other solutions may include more sophisticated php/scripts but the result will be the same. The only drawback is the missing * (asterisk) on required elements but this will show up upon the first unsuccessful request…