'Cannot be blank' Error on Required Field even if not empty?

AJAX Validation was working correctly in one of the forms in my application. Suddenly it started showing ‘cannot be blank’ on a non-empty required field. Here’s the screenshot.

It’s a crazy behavior really. It was working all fine until I made changes in the table of the concerned ActiveRecord. But the changes have nothing to do with the ‘name’ and ‘description’ fields shown in the screenshot.

Here’s the code in the view for these two fields.



<div class="row">


	<?php echo $form->label($group,'name'); ?>


	<?php echo $form->textField($group,'name',array('maxlength'=>100, 'style'=>'width:200px;')); ?>


	<?php echo $form->error($group,'name'); ?>


</div>


<div class="row">


	<?php echo $form->label($group,'description'); ?>


	<?php echo $form->textArea($group,'description',array('style'=>'width:300px; height:40px;')); ?>


	<?php echo $form->error($group,'description'); ?>


</div>

What could be the reason for JavaScript not understanding that the fields are not empty?

This code seems fine… can be something in the validation rules… or the controller action…

Here’s the code for rules.



return array(


	array('id, name, description', 'required'),


	array('id', 'length', 'max'=>36),


	array('name', 'length', 'max'=>50),


	array('user_name', 'length', 'max'=>60),


	array('rules_flag', 'length', 'max'=>1),


	array('description, attributes, filters, needles, date_entered, date_modified', 'safe'),


);

And controller action is exactly the way it was when the code was working fine.



public function actionCreate($listId)


{


	$group = new Group;


	$this->performAjaxValidation($group);


   		


	if(isset($_POST['Group']))


	{


          ....


	}


	


	$this->render('create', array(


		'group'=>$group,


	));


}




The only change I made was to the table. But I just added 3 new columns. The table remains as it is otherwise.

Restarted the server and cleared all browsing data and checked again. Same error.

Issue Resolved!

Again, I did not change anything. It started working fine on its own.

May be something wrong with charset? Could you show more code? Whole view, AR and action code?

PS. And why you use ‘safe’ rule for ‘dwscription’, if it’s already has a rule?

Hi friends, I have same problem

[b]Rules:

[/b]




	public function rules()

	{

		return array(

			array('content', 'required', 'message'=>'*'),

			array('title, category, sub_category, imageName', 'required', 'message'=>''),

			array('imageAlt, imageTitle', 'safe'),

			array('compress', 'boolean'),

			array('imagesLink','length'),

			array('imageWidth, imageHeight,watermarkXPos, watermarkYPos, watermarkOpacity',

				'numerical','integerOnly'=>true,'message'=>''),

			array('id, title, content, category', 'safe', 'on'=>'search'),

		);

	}



[b]

_form[/b]




<?php

/* @var $this ArticleController */

/* @var $model Article */

/* @var $form CActiveForm */

?>


<script type="text/javascript">

	$(document).ready(function(){	

    	$('#Article_content').hide();

		CKEDITOR.replace( 'Article_content',{enterMode : CKEDITOR.ENTER_BR,});		

		

		$.ajax({

        	type: 'GET',

        	url: base_url + "index.php?r=article/LoadSubCategories",

        	data: {

            	//parent_id: $('#Article_sub_category').find("option:selected").text(),

            	parent_id: $('#Article_category').find("option:selected").text(),

        	},

        	success: function(data){

            	$('#Article_sub_category').html(data);

            	$('#Article_sub_category').val("<?php echo $model->sub_category ?>");

        	},

    	});			

	});

</script>


<div class="form wide">


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

	'id'=>'article-form',

	'enableAjaxValidation'=>false,

	'enableClientValidation'=>true,

	'clientOptions'=>array(

		'validateOnChange'=>true,

		'validateOnSubmit'=>true,

	),

)); ?>


	<div class="row">

		<?php echo $form->label($model,'title'); ?>

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

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

	</div>


	<div class="row">

		<?php echo $form->label($model,'imageAlt'); ?>

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

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

	</div>


	<div class="row" style="clear:none">

		<?php echo $form->label($model,'imageTitle',array('style'=>'width:100px')); ?>

		<?php echo $form->textField($model,'imageTitle',array('style'=>'width:280px')); ?>

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

	</div>


	<div class="row">

		<?php echo $form->checkBox($model,'compress',array('style'=>'')); ?>

		<?php echo $form->label($model,'compress',array('style'=>'width:125px;margin-left:50px')); ?>

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

	</div>	

	

	<div class="row" style="clear:none">

		<?php echo $form->label($model,'imageWidth',array('style'=>'width:120px')); ?>

		<?php echo $form->textField($model,'imageWidth',array('style'=>'width:35px;text-align:center')); ?>

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

	</div>

	

	<div class="row" style="clear:none">

		<?php echo $form->label($model,'imageHeight',array('style'=>'width:120px')); ?>

		<?php echo $form->textField($model,'imageHeight',array('style'=>'width:35px;text-align:center')); ?>

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

	</div>

	

	<div class="row">

		<?php echo $form->label($model,'watermarkXPos',array('style'=>'width:120px')); ?>

		<?php echo $form->textField($model,'watermarkXPos',array('style'=>'width:25px;text-align:center')); ?>

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

	</div>	


	<div class="row" style="clear:none">

		<?php echo $form->label($model,'watermarkYPos',array('style'=>'width:120px')); ?>

		<?php echo $form->textField($model,'watermarkYPos',array('style'=>'width:25px;text-align:center')); ?>

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

	</div>	


	<div class="row" style="clear:none">

		<?php echo $form->label($model,'watermarkOpacity',array('style'=>'width:120px')); ?>

		<?php echo $form->textField($model,'watermarkOpacity',array('style'=>'width:25px;text-align:center')); ?>

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

	</div>	

		

	<div class="row">

		<?php echo $form->label($model,'imagesLink',array('style'=>'width:120px')); ?>

		<?php echo $form->textField($model,'imagesLink',array('style'=>'width:500px;text-align:left')); ?>

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

	</div>	

	

	<div class="row">

		<?php echo $form->label($model,'category',array('style'=>'width:60px'))?>

		<?php $cats = unserialize(CATS) ?>

		<?php echo $form->dropDownList($model,'category',array_keys($cats),array(

			'prompt'=>Yii::t('app','Select Category'),

				'ajax'=>array(

				'type'=>'GET',

				'url'=>$this->createUrl('article/LoadSubCategories'),

				'update'=>'#Article_sub_category',

				'data'=>array(

					'parent_id'=>'js:$(this).find("option:selected").text()',

				),

			),			

		))?>

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

	</div>


	<div class="row" style="clear:none">

		<?php echo $form->label($model,'sub_category',array('style'=>'width:60px'))?>

		<?php $cats = unserialize(CATS) ?>

		<?php echo $form->dropDownList($model,'sub_category',array(),array(

			'prompt'=>Yii::t('app','Select Sub Category')			

		))?>

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

	</div>	

	

	<div class="row" style="clear:none">

		<?php echo $form->label($model,'imageName',array('style'=>'width:80px')); ?>

		<?php echo $form->textField($model,'imageName',array('style'=>'')); ?>

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

	</div>

	

	<div class="row">

		<?php //echo $form->label($model,'content'); ?>

		<!-- <div class="clear"></div><br> -->

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

		<?php echo $form->textArea($model,'content'); ?>

	</div>	


	<div class="row buttons">

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

	</div>


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


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



The error raised on content attribute. textArea will replaced with CKEditor. what’s the problem?