Closed (fixed)
Project:
Address Field
Version:
7.x-1.0
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
23 Jan 2015 at 14:17 UTC
Updated:
7 May 2015 at 17:34 UTC
Jump to comment: Most recent
The default country value is lost when upgrading from 7.x-1.0-rc1 to 7.x-1.0.
With 7.x-1.0-rc1 I have a "Postal address" field with the following under "Default value":
Country: United States
Address 1:
Address 2:
City:
State: - None -
After upgrading to 7.x-1.0 and applying database updates (7001):
Default country: - None -
Comments
Comment #1
bojanz commentedGuessing your field was optional ("Required" wasn't selected).
The update function sets the default country to "- None - " for optional fields, so that by default the addressfield is saved empty unless the customer selects the country and enters the address.
You're free to set your field as "required", or select a default country (showing it selected by default, but still allowing the customer to select "None" and avoid selection).
Comment #2
aohrvetpv commentedThanks for the response. The field that loses the default value is actually required.
Steps to reproduce:
This seems to me to be a bug, because a specific configuration setting made in 7.x-1.0-rc1 is lost without warning. The field becomes incorrect after upgrade--its default value has changed from what it was set to be.
Comment #3
bojanz commentedThere's a bug then, thanks for confirming.
Comment #4
Bios450 commentedI have the same problem ...
Tell me how to solve it? or this bug will be fixed in the next version?
Comment #5
bojanz commented@Bios450
The data has been lost so it can't be fixed, you need to edit your field and set the default country again.
Comment #6
Bios450 commented@bojanz
Country I have already done ...
whether I can put the city by default?
Comment #7
bojanz commented@Bios450
That is no longer possible through the UI, you will need to use hook_addressfield_default_values_alter(), as documented in addressfield.api.php
Comment #8
aohrvetpv commentedIs the better remedy to improve the existing update function so it preserves default country, or just force administrators to re-enter the default country?
I don't see any downside to improving the update function. Users who already updated will be out of luck, but it could prevent a problem for users who have not yet updated.
Comment #9
bojanz commented@AohRveTPV
We need to fix the update function for sure. Not arguing with that.
Comment #10
redeight commentedAlso, shouldn't it default to the only available country when only one country is allowed? Seems really bizarre to have the only options be "none" and "COUNTRY A"... Seems like it should just use "COUNTRY A" in that case
Comment #11
bojanz commented@RedEight
The "- None -" option is there so that you can indicate that the field is empty. If you set the field as required, that option won't be there.
Comment #12
redeight commentedAre you sure? I've set the field to required and it still shows the country box and defaults selection to none. I will note that I am doing this inside of a webform through addressfield_tokens. So it may be an incompatibility on their end. Since the new country selector shows up I think it has to do with this module rather than that one.
Comment #13
ReBa commentedFor me, #2 worked perfectly.
Had 1 country selectable, together with 1 option that was "none" after the update.
Changing the default value worked, if anything has been updated before, data was lost.
Thanks Bojanz.
Comment #14
devad commentedPHP log message notice for this issue:
Notice: Undefined index: country in addressfield_update_7001() (line 206 of /home/mysite/public_html/sites/all/modules/addressfield/addressfield.install).
Comment #15
owenpm3 commentedI'm also not getting a default country even though I've set a default country and marked it as required. This error comes up.
Warning: Missing argument 2 for addressfield_default_values(), called in C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield_tokens\addressfield_tokens.components.inc on line 120 and defined in addressfield_default_values() (line 375 of C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield\addressfield.module).
Notice: Undefined variable: instance in addressfield_default_values() (line 376 of C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield\addressfield.module).
Notice: Undefined index: bundles in _addressfield_country_options_list() (line 874 of C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield\addressfield.module).
Warning: Invalid argument supplied for foreach() in _addressfield_country_options_list() (line 874 of C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield\addressfield.module).
Notice: Undefined variable: instance in addressfield_default_values() (line 377 of C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield\addressfield.module).
Notice: Undefined variable: instance in addressfield_default_values() (line 404 of C:\Bitnami\wampstack-5.4.37-0\apache2\htdocs\sbe\sites\all\modules\addressfield\addressfield.module).
Comment #17
bojanz commentedI've pushed a fix for the update function.
I'll commit a fix for people who already lost the default_country in #2415627: Empty default_country causes issues when the field is required.