<?php use_javascripts_for_form($form) ?>
<script type="text/javascript">
- $(document).ready(function(){
- $('#office_City_Region_country_id').change(function() {
- $.post('<?php echo url_for('office/chosencountry') ?>', { 'countryId': $(this).val() },
+ function onChangeCountry(node) {
+ if (node.val())
+ {
+ $('#office_City_Region_country_id option[value=""]').remove();
+ $.post('<?php echo url_for('office/chosencountry') ?>', { 'countryId': node.val() },
+ function(data){
+ $('#office_City_region_id').empty();
+ $('#office_City_region_id').removeAttr('disabled');
+ $.each(data, function(value, key) {
+ $('#office_City_region_id').append($("<option></option>").attr("value", value).text(key));
+ });
+ onChangeRegion($('#office_City_region_id'));
+ }, "json");
+ }
+ }
+ function onChangeRegion(node) {
+ if (node.val())
+ {
+ $.post('<?php echo url_for('office/chosenregion') ?>', { 'regionId': node.val() },
function(data){
- $('#office_City_region_id').empty();
- $('#office_City_region_id').removeAttr('disabled');
- $('#office_City_region_id').append($("<option></option>").attr("value", "").text(""));
+ $('#office_city_id').empty();
+ $('#office_city_id').removeAttr('disabled');
$.each(data, function(value, key) {
- $('#office_City_region_id').append($("<option></option>").attr("value", value).text(key));
+ $('#office_city_id').append($("<option></option>").attr("value", value).text(key));
});
- }, "json");
+ }, "json");
+ }
+ }
+
+ $(document).ready(function(){
+ $('#office_City_Region_country_id').change(function() {
+ onChangeCountry($(this));
});
});
-</script>
-<script type="text/javascript">
$(document).ready(function(){
$('#office_City_region_id').change(function() {
- $.post('<?php echo url_for('office/chosenregion') ?>', { 'regionId': $(this).val() },
- function(data){
- $('#office_city_id').empty();
- $('#office_city_id').removeAttr('disabled');
- $('#office_city_id').append($("<option></option>").attr("value", "").text(""));
- $.each(data, function(value, key) {
- $('#office_city_id').append($("<option></option>").attr("value", value).text(key));
- });
- }, "json");
+ onChangeRegion($(this));
});
});
</script>
{
$this->useFields(array('city_id', 'office_street_address', 'office_zip'));
- $query = null;
- if($this->isNew())
- {
- $country = CountryTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country'));
- $region = RegionTable::getInstance()->findOneByCountryId($country->getId());
- $query = CityTable::getInstance()->getCitiesByRegionIdQuery($region->getId());
- }
-
$this->widgetSchema['longitude'] = new sfWidgetFormInputFloat();
$this->widgetSchema['latitude'] = new sfWidgetFormInputFloat();
$this->widgetSchema['city_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('City'),
- 'add_empty' => true,
- 'query' => $query));
+ 'add_empty' => true));
$this->validatorSchema['city_id'] = new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('City'),
'required' => true));
-
- $this->widgetSchema['city_id']->setAttribute('disabled', 'disabled');
+ if($this->isNew())
+ {
+ $this->widgetSchema['city_id']->setAttribute('disabled', 'disabled');
+ }
$this->setDefault('longitude', $this->getObject()->getLongitude());
$this->setDefault('latitude', $this->getObject()->getLatitude());
}
+
+ protected function doBind(array $values)
+ {
+ if($this->getObject()->isNew())
+ {
+ if (!empty($values['City']['region_id']))
+ {
+ $this->widgetSchema['City']['region_id']->setAttribute('disabled', '');
+ $this->widgetSchema['city_id']->setAttribute('disabled', '');
+ }
+ if (!empty($values['City']['Region']['country_id']))
+ {
+ $this->widgetSchema['City']['region_id']->setAttribute('disabled', '');
+ }
+ }
+ parent::doBind($values);
+ }
}