Set Limit Select In Multiple Drowpdoanlist

Hi All

I had problem I need from users to select options from drowpdownlis but i need to force them

to select min 1 option or max 3 options .

Is it possible to do that in yii ? or I need to use java script !


....

echo CHtml::dropDownList('sub_id',$model->sub_id, empty($model->section_id) ? array() : CHtml::listData(Subsection::model()->findAllByAttributes(array('section_id' => $model->section_id)),'sub_id','en_name'),array('multiple'=>'multiple'));

...



Thanks in advance

Dear Friend

Declare a validator function in the model.




public function limitSelection($attribute,$params)

    {

        if(count($this->$attribute)>3)

            $this->addError($attribute,"You are only allowed to select 3 or less items for ".$attribute);      

    }



Then declare the rules in the following way.




public function rules()

{		

	return array(	

..................other rules......................	

	        array('sub_id', 'required','message'=>"Select atleast one item for {attribute}"),			 

		array('sub_id', 'limitSelection'),			

		);

..................other rules.....................

}



FORM




//Use CActiveForm OR CHtml::activeDropDownList to properly declare the name attribute.

echo CHtml::activeDropDownList($model,'sub_id', empty($model->section_id) ? array() : CHtml::listData(Subsection::model()->findAllByAttributes(array('section_id' => $model->section_id)),'sub_id','en_name'),array('multiple'=>'multiple'));

...



Regards.

Thanks my brother seenivasan :)