How to use ajax callback on auto complete field inside a block settings form? public function blockForm($form, FormStateInterface $form_state) {
    $form = parent::blockForm($form, $form_state);
    $selected = 'value of a field';
    $form['node'] = [
      '#type' =&gt; 'entity_autocomplete',
      '#title' =&gt; $this-&gt;t('My content type'),
      '#target_type' =&gt; 'node',
      '#selection_settings' =&gt; [
        'target_bundles' =&gt; ['bundle'],
      ],
      '#ajax' =&gt; [
        'callback' =&gt; [$this, 'my_ajax_callback'],
        'wrapper' =&gt; 'my-specializations',
      ],
    ];

    $form['first_select'] = [
      '#type' =&gt; 'select',
      '#options' =&gt; [0 =&gt; 'x', 1 =&gt; 'y'],
      '#title' =&gt; 'doctor',
      '#ajax' =&gt; [
        'callback' =&gt; [$this, 'my_ajax_callback'],
        'wrapper' =&gt; 'my-specializations',
      ],
    ];

    $form['specializations'] = [
      '#type' =&gt; 'select',
      '#title' =&gt; $this-&gt;t('Specializations'),
      '#options' =&gt; $this-&gt;specialization($selected),
      '#prefix' =&gt; '&lt;div id=&quot;my-specializations&quot;&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
    ];

    return $form;
  }

 private function specialization($selected) {
    if (!empty($selected)) {
      return ['1' =&gt; 'a', '2' =&gt; 'b'];
    }
    else {
      return [];
    }
  }

  public function my_ajax_callback(array &amp;$form, FormStateInterface $form_state) {
    return $form['specializations'];
  }

The ajax call back function is not working on auto complete field. How can I make it working on the auto complete field?
And on the first-select it is working but I am getting an error:
TypeError: Argument 1 passed to Drupal\Core\Render\MainContent\AjaxRenderer::renderResponse() must be of the type array, null given, called in /var/www/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php on line 89 in Drupal\Core\Render\MainContent\AjaxRenderer-&gt;renderResponse() (line 53 of /var/www/web/core/lib/Drupal/Core/Render/MainContent/AjaxRenderer.php)
Can you someone tells me, what I am doing wrong?
To answer the title's question
  '#ajax' =&gt; [
    'callback' =&gt; '::my_ajax_callback',
    'wrapper' =&gt; 'my-specializations',
    'event' =&gt; 'change', // run ajax on change
    'keypress' =&gt; TRUE, // if set to TRUE, then the element's #ajax['event'] will be triggered if the ENTER key is pressed while the element has focus.
  ],