Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When the Postal address field is set to be required, and the Default country is set to "- None -", the country actually defaults to the first one (usually Afghanistan), instead of the option "- Select one -".
Comment | File | Size | Author |
---|---|---|---|
#15 | addressfield-empty-defaults-2565757-15.patch | 1.96 KB | c7bamford |
#6 | 2565757-6-addressfield-required-none-option.patch | 1.61 KB | sheise |
Comments
Comment #2
4p CreditAttribution: 4p commentedI agree with the above
Comment #3
roball CreditAttribution: roball as a volunteer commentedComment #4
hkovacs CreditAttribution: hkovacs as a volunteer commentedI found in function addressfield_default_values that the comment states:
"Fallback to the first country in the list if the default country is not available, or is empty even though the field is required."
I can think of no scenario where this would be relevant upon loading a new form. If the field is required, then like any other form field it should not be auto selected (especially to an incorrect option). 'Required' should be left to form validation and not auto selected.
Looking at the Country field I see that when the default is 'None' the select list contains: - Select a value -
What seems to be going on in addressfield is that the countries are loaded as a select list (in fn addressfield_default_values) without including a '-Select a value-' option which contains a key of '_none'. The likely reason this is not provided is that the validation for required would likely pass if a key of '_none' was provided...
I propose the following on line 381:
and on line 904:
Now I get the address field country select list displaying similar to the country field.
The only thing that puzzles me is why country field understands and fails validation for value = '_none', but addressfield passes value = '_none'. I know this is probably something simple but I am out of time for now...
@rszrama, hoping for your input on this. Thanks.
Comment #5
roball CreditAttribution: roball as a volunteer commentedThanks for your input #hkovacs - hope that a solution will be commited.
Comment #6
sheise CreditAttribution: sheise commentedRunning into the same issue.
@hkovacs is right - if the field is required or the previously selected value is no longer available, we shouldn't arbitrarily set it to something else.
Here's a patch to add "Select a value" option when the field instance is required.
Comment #7
sheise CreditAttribution: sheise commentedComment #8
roball CreditAttribution: roball as a volunteer commentedThank you @sheise, your patch is working fine and solves the problem!
Comment #9
hkovacs CreditAttribution: hkovacs as a volunteer commented@sheise thank you.
patch works for me.
Comment #10
roball CreditAttribution: roball as a volunteer commentedCan we get this patch committed, please?
Comment #11
reszlifor consistency, this should use theme_options_none()
something like:
Comment #12
DamienMcKennaFYI these (and other) errors also show because of bugs in Commerce Paypal, so if you use that module make sure you update to the latest -dev version (or 7.x-2.4 if it's released) to avoid filling your dblog :)
Comment #13
sheise CreditAttribution: sheise commentedExcept that theme_options_none() only supports widget types of options_buttons and options_select but not addressfield_standard so we can't use that.
Comment #14
litnrod CreditAttribution: litnrod commentedPatch #6 is currently working great
Comment #15
c7bamford CreditAttribution: c7bamford commentedPatch #6 adds "- Select a value -" as a country instead of using the empty value attribute for the form. This patch ensures that the empty value is set regardless of the state of the form.
Comment #16
DamienMcKennaPatch #15 needs a review.
Comment #17
david-urban CreditAttribution: david-urban as a volunteer commentedI have tested #15 and it works fine with Drupal Commerce. I'd recommend merging and releasing.