/**
   * Clears the country-specific form values when the country changes.
   *
   * Implemented as an #after_build callback because #after_build runs before
   * validation, allowing the values to be cleared early enough to prevent the
   * "Illegal choice" error.
   */
  public static function clearValues(array $element, FormStateInterface $form_state) {

This is great, but it only triggers if the triggering element is country_code. It doesn't run for subdivision elements.
So if you select Brazil, then a state, then a city, then change the state, you will get an Illegal choice error for the previous city.

Comments

bojanz created an issue. See original summary.

  • bojanz committed e3ea8a9 on 8.x-1.x
    Issue #2891564 by bojanz: Address::clearValues doesn't run for...
bojanz’s picture

Status: Active » Fixed

Fixed.

dww’s picture

Nice catch! Thanks for this.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.