I successfully update a field from ajax. Its declaration is the following :
$form['field_unite_de_recherche']['widget']['#ajax'] = array(
'callback' => 'ajax_equipes_from_unites_callback',
'event' => 'change',
'method' => 'html',
'wrapper' => 'edit-field-equipe-membre2-wrapper',
);
This ajaxified field is declared as in the following :
$form['field_equipe_membre2'] = [
'#type' => 'select',
'#title' => 'Equipe(s) membre rattachée(s) à '.$title,
'#options' => $options,
];
My question is: how to know and save the selected value in this ajaxified field by the user?
I tried to add another ajax declaration in this ajaxified field as in the following :
$form['field_equipe_membre2'] = [
'#type' => 'select',
'#title' => 'Equipe(s) membre rattachée(s) à '.$title,
'#options' => $options,
'#ajax' => array(
'callback' => 'ajax_save_choice_callback',
'event' => 'change',
'method' => 'html',
'wrapper' => 'edit-field-equipe-membre2-wrapper',
)
];
But the callback function is not fired. Is there a limitation of ajax function in a form?
I red a number of times that I can use the $form_sate, for instance as in the following (from Ajax call with Submit loses submitted form data)
$value = $form_state->getValue('field_equipe_membre2');
$testArray = array('field_equipe_membre2' => $value);
$form_state->setStorage($testArray);
But the callback is not fired.
Can I have some advices?