Ajax callback, dynamic select and illegal choice

Hello,

i got some issues with my form

  public function buildForm(array $form, FormStateInterface $form_state, $id = NULL) {
$form['type_formation'] = array(
            '#type' => 'select',
            '#title' => ('Choisissez le type de formation :'),
            '#options' => $options,
            '#default_value' => $id,
            '#prefix'=>'<div class="col-lg-8">',
            '#suffix'=>'</div>',
            '#required'=> true,
            '#ajax' => [
                'callback' =>'DrupalformationFormFormationForm::changedateformation',
                'event' => 'change',
                'wrapper' => 'date-options-wrapper'
            ],
            'progress' => array(
                'type' => 'throbber',
                'message' => NULL,
            ),
        );
        $form['date_formation'] = array(
            '#type' => 'select',
            '#title' => ('Choisissez une date :'),
            '#required'=> true,
            '#prefix'=>'<div class="col-lg-6" id="date-options-wrapper">',
            '#suffix'=>'</div>',

        );
.... 
}
   public function changedateformation(array $form, FormStateInterface $form_state){
     
            /* my request with variables $date_debut $date_fin */
foreach ($nids as $nid) {
            if($nbPlaceRest > 0)
            {
                $options[$node->get('vid')->getValue()[0]['value']] = $date_debut .' au '.$date_fin.' ('.$nbPlaceRest.' place(s)).';
            }
        }
        $form['date_formation']['#options'] = $options;
        $form_state->setRebuild();
        return $form['date_formation'];
    }

my second select is corectly replaced when i chose an item in the first select, but when i submit i got error :
illegal choice has been detected…
in the reports i see it’s the second select which is the problem. Someone has an idea?
i think the form is’nt rebuild correctly, the options are not reloaded so i got this message, but i dont know how to reload correctly the $form[‘date_formation’].

thanks by advance and sorry for my english.

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed