diff --git a/src/Plugin/Field/FieldWidget/BrAddressWidgetType.php b/src/Plugin/Field/FieldWidget/BrAddressWidgetType.php
index acf7962..1b2dcba 100644
--- a/src/Plugin/Field/FieldWidget/BrAddressWidgetType.php
+++ b/src/Plugin/Field/FieldWidget/BrAddressWidgetType.php
@@ -10,6 +10,8 @@ use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Messenger\MessengerTrait;
 use GuzzleHttp\Client;
 use Drupal\Component\Utility\NestedArray;
+use Drupal\Core\Ajax\AjaxResponse;
+use Drupal\Core\Ajax\InvokeCommand;
 
 /**
  * Plugin implementation of the 'br_address_widget_type' widget.
@@ -284,75 +286,58 @@ class BrAddressWidgetType extends WidgetBase {
   }
 
   /**
-   * Call the function that consume the webservice.
+   * Call the function that consumes the web service.
    *
    * @param array $form
-   *   A form that be modified.
+   *   A form that will be modified.
    * @param \Drupal\Core\Form\FormStateInterface $form_state
    *   The values of the form.
    *
-   * @return array
-   *   The form modified
+   * @return \Drupal\Core\Ajax\AjaxResponse
+   *   The modified AjaxResponse.
    */
-  public function ajaxConsultZip(array $form, FormStateInterface $form_state) {
-    $field_name = $this->fieldDefinition->getName();
+  public function ajaxConsultZip(array &$form, FormStateInterface $form_state) {
+    $ajax_response = new AjaxResponse();
+
     $parent_keys = $form_state->getTriggeringElement()['#array_parents'];
+    $parent_field_name = $parent_keys[0];
     $form_state_values = $form_state->getValues();
 
+    // Retrieve the postal code based on parent keys.
     $elements = $this->createArray($parent_keys, $form_state_values);
     $postal_code = NestedArray::getValue($elements, $parent_keys);
-    $response = $this->consultZip($postal_code);
-
-    $form = $this->getForm($form, $parent_keys, $field_name);
-
-    if (!isset($response->erro)) {
-      $form['widget'][0]['postal_code']['#value'] = $response->cep;
-      $form['widget'][0]['thoroughfare']['#value'] = $response->logradouro;
-      $form['widget'][0]['number']['#value'] = '';
-      $form['widget'][0]['street_complement']['#value'] = '';
-      $form['widget'][0]['neighborhood']['#value'] = $response->bairro;
-      $form['widget'][0]['city']['#value'] = $response->localidade;
-      $form['widget'][0]['state']['#value'] = $response->uf;
-    }
-    else {
-      $this->messenger()->addError($this->t('Postal code not found.'));
 
-      $form['widget'][0]['postal_code']['#value'] = '';
-      $form['widget'][0]['thoroughfare']['#value'] = '';
-      $form['widget'][0]['number']['#value'] = '';
-      $form['widget'][0]['street_complement']['#value'] = '';
-      $form['widget'][0]['neighborhood']['#value'] = '';
-      $form['widget'][0]['city']['#value'] = '';
-      $form['widget'][0]['state']['#value'] = '';
+    // Call your web service function and get the new values.
+    $consulta_cep_response = $this->consultZip($postal_code);
+
+    if (!isset($consulta_cep_response->erro)) {
+
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][postal_code]\"]", 'val', [$consulta_cep_response->cep]));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][thoroughfare]\"]", 'val', [$consulta_cep_response->logradouro]));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][number]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][street_complement]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][neighborhood]\"]", 'val', [$consulta_cep_response->bairro]));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][city]\"]", 'val', [$consulta_cep_response->localidade]));
+      $ajax_response->addCommand(new InvokeCommand("select[name=\"{$parent_field_name}[0][state]\"]", 'val', [$consulta_cep_response->uf]));
+      $ajax_response->addCommand(new InvokeCommand("select[name=\"{$parent_field_name}[0][state]\"]", 'change'));
+
     }
+    else {
 
-    return $form;
-  }
+      $this->messenger()->addError($this->t('Postal code not found.'));
 
-  /**
-   * Return the form array of the defined field_name.
-   *
-   * @param array $form
-   *   Form.
-   * @param array $parent_keys
-   *   Parent keys.
-   * @param string $field_name
-   *   Field name.
-   *
-   * @return array
-   *   Array.
-   */
-  private function getForm($form, $parent_keys, $field_name) {
-    $key = array_shift($parent_keys);
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][postal_code]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][thoroughfare]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][number]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][street_complement]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][neighborhood]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][city]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("input[name=\"{$parent_field_name}[0][state]\"]", 'val', ['']));
+      $ajax_response->addCommand(new InvokeCommand("select[name=\"{$parent_field_name}[0][state]\"]", 'change'));
 
-    if (isset($form[$key])) {
-      $form = $form[$key];
-      if ($key <> $field_name) {
-        $form = $this->getForm($form, $parent_keys, $field_name);
-      }
     }
 
-    return $form;
+    return $ajax_response;
   }
 
   /**
