Ajax not working in text field I made custom module that implements hook_form_alter that marks the field_text_field_1 textfield as Ajax-enabled. When a key is pressed inside the field_text_field_1, it should change the value in a second textfield: field_text_field_2.

$form['#prefix'] = '&lt;div id="my_form_submit_wrapper"&gt;';
$form['#suffix'] = '&lt;/div&gt;';


// $form['field_village']['#attributes']['id'] = 'edit-field-cities-wrapper';

$form['field_text_field_1']['widget']['#ajax'] =array(
    "callback" =&gt; "ajax_change1",
    'wrapper' =&gt; 'my_form_submit_wrapper',
    "event" =&gt; "change",
    "effect" =&gt; "fade",
);


The callback function:

function ajax_change1(array &amp;$form, FormStateInterface $form_state){
      $form['field_text_field_2']['widget'][0]['value']['#value']='hello';  
      return $form;
}


But it's not changing the value of `field_text_field_2 to "hello".
You need to declare on what object (or class if static) to call the callback, like

'callback' =&gt; [get_called_class(), 'settingsAjax']


or 

'#ajax' =&gt; [
            'callback' =&gt; [get_class($this), 'addMoreAjax'],
            'wrapper' =&gt; $wrapper_id,
            'effect' =&gt; 'fade',
          ],


or at least

'callback' =&gt; '::settingsAjax'


depending on your code.