How to include null select option in dropdown list?

Hello,

Apologies if this is an easy answer. I’ve done some digging and couldn’t figure out how to do it. I’ve added a dropdown list in my search form that filters CGridView, but I’m not able to add a null value to the dropdown. What I’d like to have happen is that when a user selects the null option it clears the filter in the table.

2 Questions

  1. How do I add a null value to the dropdown?

  2. If the null option is selected will it clear the filter automatically or should I add some JQuery to clear the value in the filter?

Thanks for your help.

Search form


	

<div class="row">

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

		<?php echo $form->dropDownList($model,'project',$model->getProjectOptions()); ?>

	</div>




Model function for dropdown data


		

public function getProjectOptions()

	{

		$user=Users::model()->findByAttributes(array('username'=>Yii::app()->user->id));

		$accountnumber = $user->accountnumber;

		$projectsArray = CHtml::listData(Projects::model()->findAllByAttributes(array('accountnumber'=> $accountnumber)), 'internalid', 'projectname');

		return $projectsArray;

	}






<?php echo $form->dropDownList($model, 'project', $model->getProjectOptions(), array('empty'=>''); ?>



http://www.yiiframework.com/doc/api/1.1/CHtml#activeDropDownList-detail

As to the 2nd question, usually you don’t have to write something additional. :)