Monday 04 August 2008 4:07:22 pm
You could make 2 classes: Region and City. Each City has an object relation with a Region. You store regions and cities in 2 different folders. And in the edit template of your class, you add an objectrelation for region and another for city. Both relation input fields should be dropdowns. The "Region" dropdown:
<select name="region" onchange="changeCities(this.options[this.selectedIndex].value)">
{foreach $regions as $region}
<option value={$region.id}>{$region.name}</option>
{/foreach}
</select>
The "City" dropdown:
<select name="city">
{foreach $cities as $city}
<option value={$city.id} region={$city.data_map.region.content.id}>{$city.name}</option>
{/foreach}
</select>
Or something like that. And then make a javascript function called changeCities(), which hides the cities from the dropdown, that don't belong to the selected region. Of course, there's no kind of validation, so a user could actually pick a region and a city that doesn't belong to that region. Maybe there's some kind of "Related Dropdowns" datatype somewhere.
|