Address with default country code always validates as required

Created on 9 April 2020, over 4 years ago
Updated 12 November 2023, about 1 year ago

I'd like to pre-set the country code of an optional address field (typical business and/or mailing address setup), but when I set the country code in the default value, if the address is otherwise left blank, the form fails validation.

The validation error is:

6 errors have been found:
First name, Last name, Street address, City, Province, Postal code

If the address field has no country code pre-set as a default value, the empty address field validates.

I tried adapting the recipe from the cookbook (which applies to Simple Address), but it still failed with the same validation errors.

This is similar, but I believe different than these related issues:

- #2939278: Sub-elements of hidden container-type elements shouldn't be required
- #2929234: Required sub-elements in Address prevent submission when Address itself not required

advanced_address_1:
  '#type': address
  '#title': 'Advanced address - no default'
  '#description': 'This advanced address field has no default value set, and so is passes validation.'
advanced_address_2:
  '#type': address
  '#title': 'Advanced address - with default'
  '#description': 'This advanced address field has a default value (country code) set, and fails validation.'
  '#default_value':
    country_code: CA
💬 Support request
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

🇨🇦Canada leeomara Whitehorse, Yukon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia Bagz

    A simple solution is to use the Advanced settings and set a default of a single space for each of the required fields, like so:

    country_code: AU
    langcode: ''
    address_line1: ' '
    address_line2: ' '
    locality: ' '
    administrative_area: NSW
    postal_code: ' '
    given_name: null
    additional_name: null
    family_name: null
    organization: null
    sorting_code: null
    dependent_locality: null
Production build 0.71.5 2024