Ajax Callback to Update Select List not Working I have defined couple of fields inside my custom entity basefielddefinitions() like so...
$fields['product_line'] = BaseFieldDefinition::create('entity_reference')...
$fields['product'] = BaseFieldDefinition::create('entity_reference')....
Then in entity form class (ProductLineForm.php), I try to attach an ajax callback to my product_line select list such that it populates the product select list, like this
    $form['product_line']['#group'] = 'details';
    $form['product_line']['#ajax'] = [
      'callback' =&gt; '::populateProducts',
      'event' =&gt; 'change',
      'wrapper' =&gt; 'edit-products'
    ];

Then my product select list looks like this...
    $form['product']['#group'] = 'details';
    $form['product']['#attributes'] = [
      'id' =&gt; 'edit-products',
    ];

and then my populateProducts() function...
  public function populateProducts(array $form, FormStateInterface $form_state) {
    $form['product']['#options'] = ['1' =&gt; 'One', '2' =&gt; 'Two'];
    $form_state-&gt;setRebuild(TRUE);
    $response = new AjaxResponse();
    $option = &quot;&lt;option value='45'&gt;Just testing&lt;/option&gt;&quot;;
    $response-&gt;addCommand(
      new \Drupal\Core\Ajax\ReplaceCommand(
        '#edit-products',
        ($form['product'])
      )
    );
    
    return $response;
  } 

The problem is that nothing whatsoever happens, no signs of any ajax call, and the product select list stays empty as it always been.
(1)Is the the entityform class the right place for me to attach an #ajax call to a field defined in a custom entity? Or do I need a hook? Meanwhile I've done a lot of other modifications on the custom fields here in this entity form edit class (like grouping into fieldsets, vertical tabs and even modifying weight (eg $form['product_line']['#weight'] = 3 - and they all work, why not $form['product_line']['#ajax']....?
(2) Is there a way of attaching the ajax callback directly inside my custom entity's basefielddefinitions where I define the fields, I would prefer that...
Really stuck on this one, folks, please could someone help me? Appreciate all your input, Thank you all.
just got this sorted out! Decided to drill down to the array structure of the form, and found out that the #ajax element had to be attached to the widget array of the field, like this...
$form['product_line']['widget']['#ajax'] = [...]
Now it works. Another reason I keep crying &quot;better documentation for Drupal&quot;!!! How in the world was anybody supposed to know that for existing form fields, this was the format for adding Ajax?!!! Oh well, thanks community  for pointing in the right direction. Anybody knows the right place to insert this in the existing documentation? Cheers all.