Multilevel Select Extension using mcDropdown

Ok this one I just did a few hours ago; my second extension; you use it on a form that requires the user to select from a multilevel field (like a category); check the image attached to see a preview.

it shows as follows; and returns a hidden field with the value named as it should on the form.

You can use it as follows:




		<? $this->widget('application.extensions.mcdropdown.McDropdown',array(

			'model'=>$model,

			'attribute'=>'division',

			'form'=>$form,

			'data' => categorias::getData(),

			));?>

        <?



the form is a CActiveForm for easy form implementation (lol, is what I needed); the data has to be an array of data as follows:




array(

  "text"=>"Whatever Text"

  "id" =>22

  "children"=>array(

    "text"=>"son"

   ... and so on

  )

)



I use this function to get it from a table that has a parent field at a model… you may adapt it as needed.




		public function getData($cnd=" is NULL") {

			$data = array();			

             foreach(categorias::model()->findAll('parent'.$cnd) as $model) {

				$row['text'] = $model->descripcion_en;

				$row['id'] = $model->catid;

				$row['children'] = $this->getData(' ='.$model->catid);			

				$data[] = $row;

             }

             return $data;

        }




download it here : www.yiiframework.com/extension/mcdropdown/

hai xalakox, i have try your extension, but not work for me…

just display blank textField like this :