Country/city Selection List

Hi all,

I have a form in which I need to allow users to select multiple Country/City values which will be input into a list. Currently I have a drop-down list for Country which populates another drop-down list for its related Cities via an ajax call. I need to allow users to select either just a county, or a country/city combination which will then be added to the list. So far the only way I can see this working is to have a button for “Add Country Only” next to the ‘Country’ drop-down list, and another for “Add Country/City” next to the ‘City’ drop-down list. Can anyone think of a better way to achieve this? At the moment it seems a little clunky.

Also, what would be the best way to display the currently selected country/city combinations? I would like the user to be able to select and remove any entries they have previously added.


change the required validation rule for city from rules() if specified. so that if the user does not select any city means there is no problem on it.

It sounds like the only requirement is the country here. So why not change your validation rules to only require Country? But allow input (make safe) the input of City?

Thanks for replying. I wasn’t as clear as I should have been. What I need is to allow the user to select as many Country or Country/City combinations as they like, and when they are done they will click the “Submit” button which will POST this data off to the controller. Currently I have implemented this with 2 drop-down lists and some javascript which dynamically appends each selection as a new div inside a “container” div. Here I am also adding a “Remove” link against each element which removes the div via javascript. It all works however it just strikes me as a little strange there is not an actual component in Yii I can use. It seems like a fairly common kind of requirement, however I could be wrong.

Thanks again.