Skip to content
Advertisement

Yii Dropdown List Empty Value as Default

I have a dropdownlist in my _form model and I want to add a empty value (which I want as default). I have the following:

In _form:

JavaScript

In Model Country:

JavaScript

Even my empty option is in the first row in dropdownlist, the 1st country in list shows as default.

I tried:

JavaScript

In this way I can choose the default option, but cant set it to empty value, just countries that came from model:items.

Any idea?

Advertisement

Answer

Are you sure that country_id property of your model is not set to anything when you print the dropdown list? The following works for me if $model instance is created using new Country() operator but not by populating properties from database:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement