Dynamic form + AjaxValidation

Hi!

here is my situation:

form is generated by this code:


<div class="form">

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

        'id'=>'upload-form',

	'enableAjaxValidation'=>true,

        'clientOptions' => array(

      'validateOnSubmit' => false,

      'validateOnChange' => false,

    ),

)); ?>


<?php

$i=0;

foreach($files as $value=>$key){


echo $this->renderPartial('_form',array(

             'i'=>$i,

            'form'=>$form,

            'songs'=>$songs,

          'files'=>$files[$i]

      ));

$i=$i+1;

}


?>

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

<?php //echo CHtml::errorSummary(array($songs,$album,$group,$tag)); ?>


        <div class="row submit">

        <?php echo CHtml::submitButton('submit'); ?>


        </div>

    <?php $this->endWidget(); ?>


</div><!-- form -->


</form>



Here is the result:


<div class="form">

<form id="upload-form" action="/music/index.php?r=upload/edit" method="post">


	


    <div class="row">

		<label for="Songs_song_name" class="required">Song Name <span class="required">*</span></label>		<input class="required" size="60" maxlength="40" name="Songs[0][song_name]" id="Songs_0_song_name" type="text" />


////////////////////////       

    

    <div class="row">

		<label for="Songs_song_name" class="required">Song Name <span class="required">*</span></label>		<input class="required" size="60" maxlength="40" name="Songs[1][song_name]" id="Songs_1_song_name" type="text" />


////////////////////////

        

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


        <div class="row submit">

        <input type="submit" name="yt0" value="submit" />

        </div>

    </form>

</div><!-- form -->


</form>



How do i make AjaxValidation work in such conditions?

Thanks!

you must enable some kind of validation (change or submit)

also your controller must be ready to validate the sent code

Yes. Its a mistake. I forgot to change it back after some experiments :)

Thing is, that such code is generated:


<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {

$('#upload-form').yiiactiveform({'validateOnSubmit':true,'validateOnChange':false,'attributes':[{'inputID':'Songs_song_name','errorID':'Songs_song_name_em_','model':'Songs','name':'song_name'}]});

});

/*]]>*/

</script>



How to change it to Songs[0][song_name] and Songs[1][song_name]…

?

I didn’t quite understand what you want to accomplish

You cannot do ajax validation of file field, it simply doesn’t work