Yii client validation not working on ajax loaded form
Since I have just wasted few hours looking for solution (I feel like this happens a lot in programming), I may as well now explain the whole thing so that others don't have to end up like me. :|
1. enableAjaxValidation in _form.php
$form = $this->beginWidget('CActiveForm', array( 'enableAjaxValidation'=>true, ...
2. performAjaxValidation in ModelController.php
public function actionCreate() { $model=new Model; $this->performAjaxValidation($model); ...
3. Let the renderPartial output the javascript
$outputJs = Yii::app()->request->isAjaxRequest;$this->renderPartial('_form', array('model'=>new Model), false, $outputJs);
4. Append the ajax loaded content
$.get(url, function(resp) { $('#content').html(resp); // !! DO NOT append the html to element that is not yet part of the document // var slide = $('<div>').html(resp); // WRONG // $('.slides').append(slide); // WRONG
Good luck.