Ajax Or Client Validation Bug On Form With Multiple Select Drop Down List

Hello to all,

I have a form (with ajax and client validation enabled) that contains some text fields and a drop down list with multiple selection.

It happens that, when I change any text field of the form, is also activated the validation of the multiple select dropdown list field, that I’M NOT changed in any way!!

This anomalous behavior occurs only on the drop down list with multiple selection (‘size’ => 5, ‘multiple’ => true, … in my case).

In fact, if I transform this field in a single select drop down list, the error does not happen.

This is the relevant code on my form:


...

...

<div class="wide form">


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

	'id'=>'category-form',

	'enableAjaxValidation'=>true,

)); ?>


	<p class="note"><?php echo Yii::t('app', 'Fields with'); ?> <span class="required">* </span><?php echo Yii::t('app', 'are required.'); ?></p>


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

	

	<div class="row">

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

		<?php echo $form->textField($model,'categoryId',array('readonly'=>'true','style'=>'background-color: #ece3e3')); ?>

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

	</div>

	

	<div class="row">

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

		<?php echo $form->textField($model,'description',array('size'=>60,'maxlength'=>200)); ?>

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

	</div>

	

	<div class="row">

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

		<?php echo $form->textField($model,'extendedDescription',array('size'=>60,'maxlength'=>1000, 'readonly'=>'true','style'=>'background-color: #ece3e3')); ?>

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

	</div>

	

	<div class="row">

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

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

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

	</div>


	<!-- begin test multiple select -->

	<div class="row">

		<?php

		//test multiple select...

		$attributes = array(

			1 => 'Attribute 1',

			2 => 'Attribute 2',

			3 => 'Attribute 3',

			4 => 'Attribute 4',

			5 => 'Attribute 5',

			6 => 'Attribute 6',

			7 => 'Attribute 7',

			8 => 'Attribute 8',

			9 => 'Attribute 9',

			10 => 'Attribute 10',

		);

		$htmlOptions = array(

				'size' => 5,

				'multiple' => true,

				'options' => array(

						1 => array('disabled' => true, 'style' => 'font-style: italic;'),

						2 => array('selected' => true),

						4 => array('selected' => true),

						6 => array('selected' => true),

						7 => array('disabled' => true, 'style' => 'font-style: italic;'),

						8 => array('disabled' => true, 'style' => 'font-style: italic;'),

				),

		);

		echo $form->labelEx($model, 'attributes');

		echo $form->dropDownList($model, 'attributes', $attributes, $htmlOptions);

		echo $form->error($model,'attributes'); 

		?>

	</div>

	<!-- end test multiple select -->

	...

	...



The attributes field is the multiple-select drop down list on which the error occurs.

You can reproduce this case simply pasting the piece of code from:


<!-- begin test multiple select -->

to:


<!-- end test multiple select -->

in any your own form.

To better explain this case I attach a screenshots (validationMultipleSelectBug.PNG) that expose this strange behavior.

Is there anyone who can help me?

Thank you, Best Regards.

Hi,

is there anyone who can help me for this case, please?

Friendliness…

Hi, is there anyone who can help me for this case?

I really need to solve this little problem!

Thanks in advance

Please add do following in your controller ajaxvalidateion

// Remove this echo CActiveForm::validate($model);

Use following and its works for me.

echo CHtml::errorSummary($model);

Happy coding.