[Resolved] Adding additional option to activeDropDownList

Hi all,

I could not find the answer to this elsewhere that was clear enough so hopefully someone here can help.

I am modifying a select form field which is being populated by the title field in another table using the code below.

<?php  echo CHtml::activeDropDownList($page,'parentId', CHtml::listData(Page::model()->findAll() , 'id', 'title') ); ?>

What I need to do is add an additional option at the top called 'None' Which I don't want to add into the table.

Can anyone suggest how this can be done?



Look at the fourth (htmlOptions) parameter for CHtml::activeDropDownList .  Although this is mostly for adding HTML attributes, there are three special option: prompt, empty, and options.  The first two look like what you want.

Thanks for the reply.

I have tried using what you have said but it is returning errors. It stats that you should define an array there but (even using the example given) it returns an error stating that it expects a string instead of an array.

Example used:

<?php  echo CHtml::activeDropDownList($page,'menu', CHtml::listData(Menu::model()->findAll() , 'id', 'title'), array('value1'=>array('disabled'=>true, 'label'=>'value 1'),'value2'=>array('label'=>'value 2'),)); ?>

Error recieved:

htmlspecialchars() expects parameter 1 to be string, array given

What have I done wrong here? I can not find any examples of where this has been used.

Try this:

<?php  echo CHtml::activeDropDownList($page,'menu', 

    CHtml::listData(Menu::model()->findAll() , 'id', 'title'), 


); ?>

Thanks Mike,

That did it. I understand the documentation a little better now.