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.
/**
* 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
Comment #3
bojanz CreditAttribution: bojanz at Centarro commentedFixed.
Comment #4
dwwNice catch! Thanks for this.