I tried to implement the function but I didn't have much luck. Ok something works, when I go to select the select list and change an option we see that ajax updates but the text field does not change, I get an HTTP 200 error in the browser console.
Initially nothing worked because having the webform a series of multi-step-wizards. Then I realized that I had to modify the access to the array in the hook_form_alter, in practice like this:
$form['elements']['PAGE_STEP_NAME']['select_list_name']['#ajax'] = [
'callback' => 'mymodule_callback_ajax',
'event' => 'change',
'wrapper' => 'edit-microchip',
'method' => 'replace',
];
$form['elements']['PAGE_STEP_NAME']['microchip']['#prefix'] = '<div id="edit-microchip">';
$form['elements']['PAGE_STEP_NAME']['microchip']['#suffix'] = '</div>';
And the same in the callback function:
$form['elements']['PAGE_STEP_NAME']['microchip']['#value'] = $value_selected;
return $form['elements']['PAGE_STEP_NAME']['subject'];
link
in this link from the official website of drupal, it is very well explained how to exploit this technology. In particular, it is written that the WRAPPER must be equal to the ID of the object to be modified with the callback. I noticed that the WRAPPER ID in the HTML code is not the same as the one I set in the hook_form_alter edit-microchip
but this id is the same in the first part then there is a random code, maybe it doesn't work for this?