Enable Client Validation

So far, I’ve enabled clientValidation in my CActiveForm widget in my view, but the validation is only working for the first model fields on my form and not the tabular fields which are from a second model… how do I enable it for the rest of the fields or do I need to write my own Javascript? I also wondered if it’s the right practise to place all form code in one page instead of something like a renderPartial for the tabular fields…

Here is my update view:


<?php //Yii::app()->clientScript->registerCoreScript('jquery'); ?>

<?php

/* @var $this BookingController */

/* @var $model Booking */

/* @var $bookingRoom BookingRoom */


$this->breadcrumbs=array(

'Bookings'=>array('index'),

$model->id=>array('view','id'=>$model->id),

'Update'

);


$this->menu=array(

array('label'=>'List Booking', 'url'=>array('index')),

array('label'=>'Create Booking', 'url'=>array('create')),

array('label'=>'View Booking', 'url'=>array('view', 'id'=>$model->id)),

array('label'=>'Manage Booking', 'url'=>array('admin'))

);

?>


<h1>Update Booking <?php echo $model->id; ?></h1>


<?php //$this->renderPartial('_form', array('model'=>$model)); ?>


<div class="form">

<button id="btnAdd" type='btnAdd'>Add</button>

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

'id'=>'booking-form',

// Please note: When you enable ajax validation, make sure the corresponding

// controller action is handling ajax validation correctly.

// There is a call to performAjaxValidation() commented in generated controller code.

// See class documentation of CActiveForm for details on this.

'enableAjaxValidation'=>false, 'enableClientValidation' => true, 'errorMessageCssClass' => 'error', 'clientOptions'=> array('validateOnSubmit'=>true)


));     ?>


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


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




<div class="row">

    <?php echo $form->labelEx($model,'customerId'); ?>

    <?php echo $form->textField($model,'customerId'); ?>

    <?php echo $form->error($model,'customerId'); ?>

</div>


<div class="row">

    <?php echo $form->labelEx($model,'date'); ?>

    <?php echo $form->textField($model,'date'); ?>

    <?php echo $form->error($model,'date'); ?>

</div>


    <table id="tblData">

        <tbody>

    <?php foreach($items as $i=>$item): ?>


        <tr>


            <td>

    <div>

    <?php echo $form->labelEx($item,'id'); ?>

    <?php echo $form->textField($item,"[$i]id", array('readonly'=>true)); ?>

    <?php echo $form->error($item,'id'); ?>

</div>

                </td><td>               

            <td>

    <div>

    <?php echo $form->labelEx($item,'bookingId'); ?>

    <?php echo $form->textField($item,"[$i]bookingId", array('readonly'=>true)); ?>

    <?php echo $form->error($item,'bookingId'); ?>

</div>

                </td><td>               


    <div> 

    <?php echo $form->labelEx($item,'roomId'); ?>

    <?php echo $form->dropDownList($item, "[".$i."]roomId", CHtml::listData(

    Room::model()->findAll(), 'id', 'id'), array('single'=>'single', 'size'=>1)

    ); ?>

        <?php echo $form->error($item,'roomId'); ?>


    </div>

            </td><td>

    <div>

    <?php echo $form->labelEx($item,'startDate'); ?>

    <?php echo $form->textField($item,"[$i]startDate"); ?>

    <?php echo $form->error($item,'startDate'); ?>

</div>

                </td><td>

    <div>

    <?php echo $form->labelEx($item,'endDate'); ?>

    <?php echo $form->textField($item,"[$i]endDate"); ?>

    <?php echo $form->error($item,'endDate'); ?>

</div>

    </td><td>

    <div>

    <?php echo $form->labelEx($item,'adults'); ?>

    <?php echo $form->dropDownList($item, "[$i]adults", array('1'=>'1',

                                                                 '2'=>'2',

                                                                 '3'=>'3',

                                                                 '4'=>'4',

                                                                 '5'=>'5'), array('single'=>'single', 'size'=>1)

    ); ?>


    </div>

</td><td>

            <div>

    <?php echo $form->labelEx($item,'children'); ?>

    <?php echo $form->dropDownList($item, "[$i]children", array('0'=>'0',

                                                                 '2'=>'2',

                                                                 '3'=>'3',

                                                                 '4'=>'4',

                                                                 '5'=>'5'), array('single'=>'single', 'size'=>1)

    ); ?>


    </div>

    </td>

    <td>

        <button type='button'>Delete</button>

    </td>

    </tr>

    <?php endforeach; ?>

        </tbody>

    </table>




    <div class="row buttons">

    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

</div>


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


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