Form elements created with AJAX aren't sending values through form_state I've created a AJAX block form that allows a user to specify the number of fields they would like to have available. like so

    $form['columnNum'] = [
        '#title'   =&gt; t('Number of Columns'),
        '#type'    =&gt; 'select',
        '#options' =&gt; [
            1         =&gt; '1',
            2         =&gt; '2',
            3         =&gt; '3',
        ],
        '#default_value' =&gt; $this-&gt;configuration['columnNum'],
        '#empty_option'  =&gt; t('-select-'),
        '#ajax'          =&gt; [
            'callback'      =&gt; [$this, 'columnCallback'],
        ],
    ];

    $columns = $this-&gt;colFieldGen($this-&gt;configuration['columnNum'], $this-&gt;configuration['columns']);

    $form['column_wrapper'] = [
        '#type'       =&gt; 'container',
        '#attributes' =&gt; ['id' =&gt; 'column_wrapper'],
        $columns,

    ];
return $form;


the colFieldGen form, generates the number of fields like so.

public function colFieldGen($num, array $config) {
    for ($i = 0; $i &lt; $num; $i += 1) {
        $numTitle    = $i+1;
        $columns[$i] = [
            $i             =&gt; [
                '#type'       =&gt; 'details',
                '#title'      =&gt; t('Column '.$numTitle),
                '#open'       =&gt; FALSE,
                'columnTitle' =&gt; [
                    '#type'      =&gt; 'textfield',
                    '#title'     =&gt; t('Column Title'),
                ],
            ],
          ];


And below is the callback.

public function columnCallback(array&amp;$form, FormStateInterface $form_state) {
        $response = new AjaxResponse();
        $columns = $this-&gt;colFieldGen($number, $this-&gt;configuration['columns']);

        $content = [
            '#type'       =&gt; 'container',
            '#attributes' =&gt; ['id' =&gt; 'column_wrapper'],
            $columns,
        ];

        $response-&gt;addCommand(new ReplaceCommand('#column_wrapper', $content));
        return $response;
    }


I'm using the replace command to replace the fields that were present in the container, with a set of new fields. However any of the data in the new fields aren't sent through form_state. Fields that existed already like $form['columnNum'] are sent through $form_state just fine.

Is there a way to see values of ajax created form elements in $form_state? Or is there a better way to do this entirely?

NOTE: This is all being performed in a blockForm if that makes any difference.



UPDATE:

I changed the field generator to be based on a form_state variable like so

if (empty($form_state-&gt;getValue('number'))) {
    $form_state-&gt;setValue('number', 1);
}

$columns = $this-&gt;colFieldGen($form_state-&gt;getValue('number'), $this-&gt;configuration['columns']);


and then in the AJAX call performed this

public function columnCallback(array&amp;$form, FormStateInterface $form_state) {
    $form_state-&gt;setValue('number', 10);
    $form_state-&gt;setRebuild(true);
    return $form;
}


But the form never rebuilds with the new amount of specified fields. I receive the progress animation on change, so I know something is firing. I just get no results. To see if the form was attempting a rebuild I added 

if (empty($form_state-&gt;getValue('number'))) {
    $form_state-&gt;setValue('number', 1);
} else {
    die($form_state-&gt;getValue('number'));
}


to have the form fail if the form_state already exists but it never dies.
Move all form building activities from the callback to the form build function.

The form elements you add in the callback go directly through javascript to the DOM in your browser. You see them as normal form elements, but the form API doesn't know that they are in your browser and will ignore them.

Edit for the questions in comments:

In the form build function you know that you are rebuilding because $form_state is filled with data. On the first run it is empty.

You have the number of columns in the value of the select element.

You should wait with handling of the configuration data until submit.

In general an ajax form should have the same code in form build as a normal form, because if jquery is not available, ajax will fallback to a normal rebuild.