How do I add an AJAX action on a select element in a ContentEntityForm to change the value of another select element I have a ContentEntityForm with two select elements category and data_type. I want to load the options for the second select element when the first select element changes. I have tried to add the following in the buildForm function of the ContentEntity form but this does not seem to be adding the ajax trigger to the element. Any thoughts on what I am doing wrong?

$form['category']['#ajax'] = [
  'callback' =&gt; '_ajax_form_category_change',
  'event' =&gt; 'change',
  'wrapper' =&gt; 'ajax_id_data_type',
  'method' =&gt; 'replace',
];
$form['data_type']['#prefix'] = '&lt;div id="ajax_id_data_type"&gt;';
$form['data_type']['#suffix'] = '&lt;/div&gt;';


_ajax_form_category_change is a function in my module

function _ajax_form_category_change($form, $form_state) {
  return $form['data_type'];  
}


I have also added a form_alter in my module to change the options of $form['filing_type'].
SOLUTION: Got this working with the following. You have to set the #ajax property on the widget

// Set the ajax function to run on the change of filing category.
$form['category']['widget']['#ajax'] = [
  'callback' =&gt; '_ajax_form_category_change',
  'event' =&gt; 'change',
  'wrapper' =&gt; 'ajax_id_data_type',
  'method' =&gt; 'replace',
];