I have a country field in my form. When this is set, I'd also like to update the addressfield with teh correct country value and settings. Using jquery it's easy to set the country, but this obviosuly dioesn;t trigger the addressfield rebuild. Any idea what I can do?
[The use case is where people are entering branches in countries, but where the address may be in another country, so the country and address dropdowns need to be separate e.g. the Irish branch has a GB address. However, for 99% of countries, country and address country will be the same, so to save hassle, I'd like to set the latter automatically when the former is set]
I've got:
$form['field_country'][LANGUAGE_NONE]['#ajax'] = array(
'callback' => 'my_callback',
'wrapper' => $format['#wrapper_id'],
'method' => 'replace',
);
so my_callback is fired when the country is changed, but what should it do to trigger a rebuild of the addressfield with the new country value?
Comments
Comment #1
rszrama commentedThe Address Field AJAX should be triggered any time the browser recognizes the country select list value has changed. If for some reason how you're updating that select list to match your other country select list isn't working, just use the jQuery change() method on the country select list. Make sure that the selector you're using to identify the country select list can accommodate the --# suffix added to the select list by the Forms API when the AJAX refresh rebuilds the form.