Messed-up div IDs for ajax-modified form field
function mymodule_form_NODETYPE_FORM_alter(&amp;$form, &amp;$form_state, $form_id) {
    $form['field2']['#attributes']['id'] = 'my_dom_id_for_elem2';
    // or if it doesn't work properly you can wrap the element
    // $form['field2']['#prefix'] = '&lt;div id="my_dom_id_for_elem2"&gt;';
    // $form['field2']['#suffix'] = '&lt;/div&gt;';

    $form['filed1']["widget"]['#ajax'] = array(
        'callback' =&gt; 'on_filed1_change',
        'wrapper' =&gt; 'my_dom_id_for_elem2', 
        'event' =&gt; 'change',
        'method' =&gt; 'replace',
    ); }

function on_filed1_change(array $form, FormStateInterface $form_state) {
    // This line is not necessary, at this time $form['field2']
    // has already been modified and you can just return the form element itself, it will be used as response.data by javascript.
    //$form['field2'] = $modified_field2;
    return $form['field2']; 


}