gopal
gopal

Reputation: 15

Yii combobox validation

I am developing with Yii framework

This is a part of my View

echo CHtml::dropDownList('codCity', '',$cityList);

the dropdown is filled up so that in the end, option are something like that

<option value="XX">(Select a city)</option>
<option value="RM">Rome</option>
<option value="FL">Florence</option>
...

from a validation viewpoint, the first option (XX) is not valid, while the others are valid so in my model I have

public function rules()
{
        return array(
            ...
            array('codCity', 'compare', 'operator'=>'!=', 'compareValue'=>'XX' ,
                  'message'=>'please select a city'),
            ...
    );
}

and this is the only validation rule that I apply to codCity field.

Unluckily, things are not going as I suppose, and all options are validated as 'good', even the bad one (XX)

any suggestions?

thank you so much

Upvotes: 1

Views: 1211

Answers (1)

schmunk
schmunk

Reputation: 4708

Have a look at http://www.yiiframework.com/doc/api/1.1/CHtml#dropDownList-detail

You can specfiy a prompt option.

prompt: string, specifies the prompt text shown as the first list option. Its value is empty. Note, the prompt text will NOT be HTML-encoded.

Upvotes: 1

Related Questions