commit 36dc7b0bd3555e571ba72a093f18db0a93f70d9c
Author: fago <nuppla@zites.net>
Date:   Wed Jun 27 14:25:18 2012 +0200

    form state default value patch

diff --git a/addressfield.module b/addressfield.module
index 1209a43..6c0bdb6 100644
--- a/addressfield.module
+++ b/addressfield.module
@@ -428,28 +428,11 @@ function addressfield_field_widget_settings_form($field, $instance) {
 function addressfield_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
   $settings = $instance['widget']['settings'];
 
-  // Generate a specific key used to identify this element to restore a default
-  // value upon AJAX submission regardless of where this element is in the
-  // $form array.
-  $element_key = implode('|', array($element['#entity_type'], $element['#bundle'], $element['#field_name'], $element['#language'], $element['#delta']));
-
-  // Store the key in the element array as a value so it can be easily retrieved
-  // in context in the $form_state['values'] array in the element validator.
-  $element['element_key'] = array(
-    '#type' => 'value',
-    '#value' => $element_key,
-  );
-
   // Get the default address used to build the widget form elements, looking
-  // first in the form state, then in the stored value for the field, and then
-  // in the default values of the instance.
-  $address = array();
+  // first in the stored value for the field, and then in the default values of
+  // the instance.
 
-  if (!empty($form_state['addressfield'][$element_key])) {
-    // Use the value from the form_state if available.
-    $address = $form_state['addressfield'][$element_key];
-  }
-  elseif (!empty($items[$delta]['country'])) {
+  if (!empty($items[$delta]['country'])) {
     // Else use the saved value for the field.
     $address = $items[$delta];
   }
@@ -484,28 +467,17 @@ function addressfield_field_widget_form(&$form, &$form_state, $field, $instance,
     // Mark the form element as required if necessary.
     $element['#required'] = $delta == 0 && $instance['required'];
   }
-
   return $element;
 }
 
 /**
- * Element validate callback: rebuilds the form on country change and stores the current address value in the $form_state for retrieval on rebuild.
+ * Element validate callback: rebuilds the form on country change. Form values will be kept by the form API.
  */
 function addressfield_standard_country_validate($element, &$form_state) {
   // If the country was changed, rebuild the form.
   if ($element['#default_value'] != $element['#value']) {
     $form_state['rebuild'] = TRUE;
   }
-
-  $parents = $element['#parents'];
-  array_pop($parents);
-
-  // Search through the form values to find the current address.
-  $address = drupal_array_get_nested_value($form_state['values'], $parents);
-
-  // Store the present address values in the form state for retrieval by the
-  // widget form regardless of where the widget sits in the $form array.
-  $form_state['addressfield'][$address['element_key']] = array_diff_key($address, array('element_key' => ''));
 }
 
 /**
