I’m using a form generated by yii,it contain a field named ‘Country’ and i set it to be a dropdownlist,the dropdownlist works well.but there is a default option “Please select” by the first line of the options,I want to change the words,but I can’t find where to edit,I search the whole code source of yii and webroot,but find nothing,any one can help me ,thanks a lot!
Well, for other people who may also been looking for this solution, there are several methods to solve this:
The one that ariefpriyadi used, but it has the problem of not being the best solution if the dropdownlist is multiselect. Besides, it is a model level solution for an interface issue: unless we are talking about a very sensitive decision, sometimes the default-selection is a matter of visualization only, sometimes it is a programmer’s whim to leave a default selection, but it doesn’t deeply affect the database, nor the model itself, nor the application gravely, so I think that the solution should be in the views layer.
Creating a default value in the table, is another solution that is being proposed in other threads.
This is worse, I think: it uses a database-level solution for something that is a matter of visualization (read the argument of point 1).
Another solution is using the "options" entry in the array of htmloptions, I read it in the CHtml Dropdownlist (http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail) documentation, but I applied it for an ActiveForm Dropdownlist. So in this example, if the reader wants the item with key value "3" tobe selected by default, she/he should use:
Best Regards, and let me congratulate once more the founders of this absolutely great framework. Is there a way to make a monetary donation to this project? I’ve been earning money with it…
I want to set Default Value in above list i.e Parent with value 0 But I have defined 0 value in table for parent_id when i am using array(‘0’=>‘Parent’) it inserting nothing in table means not set. EVEN If array(‘empty’=>‘Parent’) also shows error of not inserting empty value to DB , keeping parent_id in rules() safe also Not working…