I've noted that there is some unusual default value handling via the $form_state, which gets prioritized compared to the other default value. Keeping the default value there shouldn't be necessary, but created troubles for me when I tried to use the addressfield in a multi-step form as the form-state default value overwrote the #default_value key.

Patch to remove it attached.

Comments

fago’s picture

StatusFileSize
new3 KB

updated the patch to do more cleanup, i.e. also fixed some comments and remove some more unnecessary code

In my tests the addressfield continued to behave properly in ajax callbacks and field api add-more handling.

fago’s picture

I just ran into an issue where an addressfield got populated with wrong default values when an addressfield is part of an embedded field-collection and a new one gets added. This patch fixed the issue :)

kepford’s picture

Just discovered the same issue on one of my client's sites. My issue was with the Commerce order edit page. I have an addressfield on each line item. If you have multiple line items on an order the last addressfield saved will be used as the default for the other line items address fields. This patch appears to have fixed the issue for me.

Thank you for the patch fago!

colan’s picture

jody lynn’s picture

I had a multiple field collection containing an addressfield and the addresses were picking up default values from the first one entered. The first patch here fixed it (the one in comment 1 would no longer apply). the patch in #1285980: hook_form_alter() doesn't affect #default_values as expected did not fix it.

jody lynn’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs review
dgtlmoon’s picture

$ cat addressfield_default_0.patch |patch -p1

patching file addressfield.module
Hunk #1 succeeded at 479 (offset 51 lines).
Hunk #2 FAILED at 467.
1 out of 2 hunks FAILED -- saving rejects to file addressfield.module.rej
swentel’s picture

Status: Needs review » Needs work

This doesn't seem todo the trick. For instance, add 'Canada' as a country. If you switch from say Belgium to Canada, the province field for canada doesn't show up at all.

bojanz’s picture

Title: unusual default value handling via form state » Stop duplicating form state values in $form_state['addressfield']

Retitling.
The patch is incomplete, $address still needs to be populated from form state because the handlers will need the updated values in order to rebuild the country-specific fields properly.
However, there's no reason why we can't take the new $address from $form_state directly, instead of duplicating the values in $form_state['addressfield'].
The field_collection issues are caused by the element_key being less granular than #parents.

bojanz’s picture

Status: Needs work » Fixed

Completed the patch, tested it, committed: http://cgit.drupalcode.org/addressfield/commit/?id=300c30e

  • bojanz committed 300c30e on 7.x-1.x
    Issue #1662680 by fago: Stop duplicating form state values in $...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.