Form Rebuild by Ajax Call I have a form which is built using some data which is partially random. Unfortunately, at the first AJAX call (nothing has been submitted yet, neither AJAX, nor in the normal way) the form will be rebuilt so that all random inputs are lost. Is there any way to avoid it?

class AjaxTestForm extends FormBase {

  public function getFormId() {
    return 'ajax_text_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state) {
    $options = $this-&gt;_getOptions();
    $form['select'] = [
      '#type' =&gt; 'select',
      '#title' =&gt; 'Select',
      '#options' =&gt; $options,
      '#ajax' =&gt; [
        'callback' =&gt; [$this, 'ajaxCallback'],
      ],
      '#empty_option' =&gt; 'Please select',
      '#required' =&gt; TRUE,
    ];
    $form['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; 'Save',
    ];
    $form_state-&gt;set('ajaxoptions', $options);
    return $form;
  }

  private function _getOptions()
  {
    // Actually data from an external Controller
    // But those, too, are random
    $options = [
      mt_rand(1000, 9999),
      mt_rand(1000, 9999),
      mt_rand(1000, 9999),
    ];
    return $options;
  }

  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    // Do nothing
  }

  public function ajaxCallback($form, $form_state)
  {
    print_r($form_state-&gt;getValue('select'));
    echo "\n";
    print_r($form['select']['#options']);
    print_r($form_state-&gt;get('ajaxoptions'));
  }

}


When the user selects an option, in the Ajax callback (or Ajax submit, if I had one) I can't know which options were originally in the select box available. 
Is there any way to preserve that information?
Get the value from:

$_temp_var_ = $form_state-&gt;getUserInput('_field_name_');

Use getUserInput() instead of getValue().

And then set the value to:

$form['_field_name_'] = $_temp_var_;