Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii- client side validation is not working on CActiveForm

I've an active form in my application. But the client side validation is not working. The code of the form are as shown below:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'application-data-student-form',
    'enableAjaxValidation'=>false,
    'enableClientValidation'=>true,
    'clientOptions'=>array('onSubmit'=>true),
    'htmlOptions'=>array(
        'enctype'=>'multipart/form-data',
        'role'=>'form',
        'class'=>'form-horizontal'
    ),
)); ?>

I've used bootstrap 3 in my project. Any idea or solution will be highly appreciated from anybody . . .

like image 581
dlthp Avatar asked Jun 03 '14 11:06

dlthp


2 Answers

I've finally resolved the problem. I'm posting this so that it may help someone with the same problem.

The problem was caused because jquery.js was not loaded properly in the application. The map file was missing that is required by the jquery.js. So I downloaded the latest jquery 2.1.1.min.js & respective map file from [http://jquery.com/download/] and loaded them in the main layout. Now the validation is finally working.

Hope this workaround will help someone with same problem.

like image 178
dlthp Avatar answered Nov 14 '22 20:11

dlthp


Try add in model action something like this:

if (Yii::app()->request->isAjaxRequest){
    echo CActiveForm::validate($model);
    Yii::app()->end();
}

or uncoment this line

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
like image 1
mosvov Avatar answered Nov 14 '22 21:11

mosvov