I have a custom form and want to use the 'address' field type on it, I'm using the example found in the feature request for the field:
$form['bill_address'] = array(
'#type' => 'address',
'#title' => $this->t('Billing Address'),
'#default_value' => [
'given_name' => 'John',
'family_name' => 'Smith',
'organization' => 'Google Inc.',
'address_line1' => '1098 Alta Ave',
'postal_code' => '94043',
'locality' => 'Mountain View',
'administrative_area' => 'CA',
'country_code' => 'BE',
'langcode' => 'en',
],
'#available_countries' => ['DE', 'FR', 'US'],
);
The default shows up fine at first, showing all the fields.
When selecting a new country, all the fields disappear, the "please wait" widget is shown for a second and then disappears again but nothing else happens.
Re-selecing the default-country doesn't make the fields re-appear either.
Tried on Chrome regular and incognito and Firefox, same issue everywhere.
Console tab is not showing anything.
Form with default values:

Form after selecting a country:

Comments
Comment #2
Pascal- commentedComment #3
Pascal- commentedDid some debugging, but can't really figure it out myself.
I logged this in processAddress.php:
Took screenshots of all the log results:
https://gyazo.com/collections/invitations/3255814c0157b2d6cc08343945f45a9f
Comment #4
dwwWell, that's interesting. At #2689089-10: Define a form element type "address" bojanz said:
I tried to reproduce this by hacking my copy of devel.module to add a bogus address form element to the devel settings form. I'm seeing exactly the buggy behavior described in the original post. Haven't had a chance to actually debug, but wanted to confirm and provide a quick patch that should make it easy to reproduce this if anyone's interested in digging further. I'm assuming you have devel installed. ;)
Note: the code in the OP uses 'BE' for the country code, even though it's obviously a US address. My patch uses the correct country for the default value. However, the bug is present in both cases.
Comment #5
bojanz commentedThe form element works when embedded inside another form element (commerce_profile_select), but on the Devel form, core just ignores all input (hence no country_code and no elements). I managed to briefly catch a glimpse of address properties appearing in user input one level above where they should be, as if $element['#parents'] isn't respected, but the code looks fine. Tried to disable the groupElements/clearValues code in case the bug was there, but no change.
It's even more visible if no #element_value is provided.
First hour wasted. To be continued.
EDIT: I should also note that the form element works inside the field widget (AddressDefaultWidget), and the tests are passing, yet I see no obvious difference between the two "environments".
Comment #6
bojanz commentedAdding $form['#tree'] = TRUE; to the SettingsForm solves it, looks like the problem is that the form element does not always enforce '#tree' => TRUE for itself (in the process method). That causes the form values to show up in the wrong place
Comment #7
bojanz commentedTry this.
Comment #8
bojanz commentedComment #9
dwwNice! Confirmed this solves it on my local site. Code looks clean (duh). RTBC.
Thanks,
-Derek
Comment #10
dwwComment #11
bojanz commentedCommitted, thanks!