Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: Allow addresses to not have a default country code #15761

Open
ryssbowh opened this issue Sep 19, 2024 · 0 comments
Open

[4.x]: Allow addresses to not have a default country code #15761

ryssbowh opened this issue Sep 19, 2024 · 0 comments

Comments

@ryssbowh
Copy link

ryssbowh commented Sep 19, 2024

What happened?

Description

I've got a user facing form for saving addresses where they have to select their country, the client wants to force the users to choose one but start with an empty value.

When sending the form without country for validation I'm not getting an error on the country because it takes "US" by default, even though the user has not chosen one. Sending an empty string as countryCode does not replace the country in the address before it's validated.

I also tried to set an empty string to the config defaultCountryCode but I then get a 500 :

"name":"Exception"
"message":"Missing required property country_code."
"code":0
"error":"Missing required property country_code."
"exception":"InvalidArgumentException"
"file":"/var/www/html/vendor/commerceguys/addressing/src/AddressFormat/AddressFormat.php"
"line":120

Does this sound like a possible change ?

Steps to reproduce

  1. set the config defaultCountryCode to an empty string
  2. Save an address without country

Expected behavior

I'm getting a validation error "The country field is required"

Craft CMS version

4.12.1

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant