Using the same form more than once per page with AJAX callbacks
Define a class property for a sub id and append it to the form id:

class MyForm extends FormBase {

  public $sub_id = '0';

  public function getFormId() {
    return 'my_form_' . $this-&gt;sub_id;
  }

  ...
}


You can append this sub id to the wrapper as well, if you want to have different wrappers for each form:

  public function buildForm(array $form, FormStateInterface $form_state) {
    $wrapper = 'ajax-wrapper-' . $this-&gt;sub_id;
    // use $wrapper for #ajax and div container in buildForm()
    ...
  }


Then set a different sub id for each instance of the form.

For example in a block the first instance:

$form = \Drupal::classResolver()-&gt;getInstanceFromDefinition('Drupal\mymodule\Form\MyForm');
$form-&gt;sub_id = '1';
$build['form'] = \Drupal::formBuilder()-&gt;getForm($form);


and the second in preprocess:

$form = \Drupal::classResolver()-&gt;getInstanceFromDefinition('Drupal\mymodule\Form\MyForm');
$form-&gt;sub_id = '2';
$variables['form'] = \Drupal::formBuilder()-&gt;getForm($form);