Closed (fixed)
Project:
Address
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
7 Jul 2022 at 17:54 UTC
Updated:
4 Aug 2023 at 18:44 UTC
Jump to comment: Most recent
My use case is this:
I'm guessing this is the case for very many vendors, so I'm not sure how this keeps getting jammed up.
I swear this was possible previously, but maybe I'm misremembering.
Please can we make this happen without having to implement custom code?
Comments
Comment #2
Anonymous (not verified) commentedI've tried replicating this issue using the development version of this module, PHP8.0.10 and Drupal 9.4.5.
I've enabled the module, added the non-required address field to the content type and set the Country default value with the option provided in the field setup. Then I've checked if the Countries default value gets populated and it is.
I am wondering whether you've been using any custom code or other module that interacts with the address field?
Comment #3
aaronbaumanYes, the other address values are optional, but the address data is still saved, and the address considered "not empty" if a country is selected.
Maybe a better way to describe the request is: "Allow fields other than country to indicate whether the address field is empty"
Comment #4
igork96 commentedI tested this and it works properly. Maybe you can set the fields (name, city, street) as required so you'll always have a legit address. Can you be more specific on how you intend to use this? ( why allow the user to save an address with just the country filled)
Comment #5
igork96 commentedComment #6
swentel commentedI more or less had the same use case too. I solved it by creating my own widget, where I override the form element and massage form values to only save the address field when postal code and locality had a value.
I also override the field_overrides for delta 0 and a specific field to make that one required. If you don't need that, you can leave out that code of course.
Comment #7
fallenturtle commentedThis is something I need a solution for as well. I'd like to have the field not be required, but also not make my fully domestic audience select the country when they want to add an address. If I select the country to default to United States, then the rest of the address field becomes required.
Comment #8
bojanz commentedA custom solution like #6 is the only way.
We can't preselect the country without making the field required. We tried many hacks in the early addressfield days but nothing truly worked for everyone.