Drupal 8: Form fields are not updating when checking triggering element I have added a button to the node add form which allows the user to import data from the last node created into this one. Within hook_form_alter, I have:

// Import previous month's data if requested
$trigger = $form_state-&gt;getTriggeringElement(); //Check to see if button pressed

if ($trigger['#name'] == 'import_previous') {
  $id = \Drupal::request()-&gt;query-&gt;get('field_patient'); //grab node id from url
  $previous = st_access_patient_get_previous($id); //grab actual node
  $previous_array = $previous-&gt;toArray(); //cast node to array

  // Match up data from previous node to fields in this form, set default value
  foreach ($previous_array as $label =&gt; $field) {
    if (substr($label, 0, 5) == 'field' &amp;&amp; $form[$label]['#access'] == TRUE) {

      if (array_key_exists('#default_value', $form[$label]['widget'])) {
        if (array_key_exists('target_id', $field[0])) {
          $form[$label]['widget']['#default_value'] =  $field[0]['target_id'];
        } else {
          $form[$label]['widget']['#default_value'] =  $field[0]['value'];
        }
      } else {
        if (array_key_exists('target_id', $field[0])) {
          $form[$label]['widget'][0]['value']['#default_value'] = $field[0]['target_id'];
        } else {
          $form[$label]['widget'][0]['value']['#default_value'] = $field[0]['value'];
        }
      }

    }
  }

}

$form['previous_import'] = [
  '#type' =&gt; 'button',
  '#name' =&gt; 'import_previous',
  '#value' =&gt; t("Import the previous month's values"),
  '#weight' =&gt; -9999,
  '#submit' =&gt; ['import_previous_submit'],
];


My understanding is that the button will just submit the form, I don't actually need

'#submit' =&gt; ['import_previous_submit']


When pressing 'import_previous' button the field values are not updated. If I remove the conditional (which just runs the replacement logic on every form load) then everything works fine. So, I know my logic for the replacement itself is correct. But once I wrap my replacement logic in:

if ($trigger['#name'] == 'import_previous') {}


Then the fields no longer update when the button is pressed. The conditional passes, so I know that is correct. Something else is keeping the form default values from being set. I have tried to add:

  $form_state-&gt;setRebuild(TRUE);
  $form_state-&gt;setCached(FALSE);


after:

$trigger = $form_state-&gt;getTriggeringElement();


and directly before the final closing tag of the conditional. I have also tried to add it to a submit function 'import_previous_submit'. No love with any of that. Any help is greatly appreciated.
You don't need to check the triggering element if you use it's own submit handler because the submit handler is only triggered by this element.

function your_module_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  $form['previous_import'] = [
    '#type' =&gt; 'submit',  // changed to submit
    '#name' =&gt; 'import_previous',
    '#value' =&gt; t("Import the previous month's values"),
    '#weight' =&gt; -9999,
    '#submit' =&gt; ['import_previous_submit'],
  ];
}

function import_previous_submit(&amp;$form, FormStateInterface $form_state) {
  // Example of altering / setting the field values. You have to adapt your foreach stuff.
  $user_input = $form_state-&gt;getUserInput();
  $user_input['title'] = [['value' =&gt; 'test']];
  $form_state-&gt;setUserInput($user_input);

  $form_state-&gt;setRebuild();
}