Continually adding fields to a form each time a button is pressed using AJAX I'm attempting to add fields dynamically to a form using AJAX in a block plugin however no action occurs when clicking on the button that is meant to add a field.
The code I'm currently is below

   class Standard extends BlockBase {
    public function blockForm($form, FormStateInterface $form_state) {
        $form_state-&gt;setCached(FALSE);
        $form['actions'] = array(
            '#type' =&gt; 'actions',
        );
        $form['column']['columnNum'] = array(
            '#type'          =&gt; 'value',
            '#default_value' =&gt; $this-&gt;configuration['columns_submit'],
        );

        $form['column_wrapper'] = array(
            '#type'       =&gt; 'container',
            '#attributes' =&gt; array(
                'id'         =&gt; 'column_wrapper',
            ),
        );
        for ($i = 1; $i &lt;= $this-&gt;configuration['columns_submit']; $i += 1) {
            $form['column'][$i] = array(
                '#type'           =&gt; 'details',
                '#title'          =&gt; t('Column '.$i),
                '#open'           =&gt; FALSE,
                'group'           =&gt; 'Content',
                'body_text'       =&gt; array(
                    '#type'          =&gt; 'text_format',
                    '#title'         =&gt; $this-&gt;t('Body'),
                    '#default_value' =&gt; $this-&gt;configuration['column'][$i]['body_text_submit']['value'],
                ),
                'class'           =&gt; array(
                    '#type'          =&gt; 'textfield',
                    '#title'         =&gt; $this-&gt;t('Class'),
                    '#default_value' =&gt; $this-&gt;configuration['column'][$i]['class_submit'],
                ),

            );
        }
        $form['addcolumn'] = array(
            '#type'     =&gt; 'button',
            '#name'     =&gt; 'Add Column',
            '#value'    =&gt; t('Add column'),
            '#submit'   =&gt; array($this, 'addColumnSubmit'),
            '#ajax'     =&gt; array(
                'callback' =&gt; [$this, 'addColumnCallback'],
                'effect'   =&gt; 'fade',
                'wrapper'  =&gt; 'column_wrapper',
            ),
        );
        return $form;
    }
    public function addColumnSubmit(array&amp;$form, FormStateInterface $form_state) {
        $this-&gt;configuration['columns_submit'] += 1;
        $form_state-&gt;setRebuild(TRUE);
    }
    public function addColumnCallback(array&amp;$form, FormStateInterface $form_state) {

        return $form['column'];
    }


Nothing occurs when clicking the $form['addcolumn'] button. I've based my attempts on examples such as this one https://www.drupal.org/node/2723033. (I understand that is an example of it not working, but based on the comments it seemed like an error that was easily fixed)
I'd like to be able to continually add fields each time the button is pressed. Is there something wrong with my code? Is there a proper way to continually add fields when a button is pressed to a form using AJAX?



Update: I made another attempt which failed as well. 

I used 

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


in BlockForm()

and 

    $numColumns = $form_state-&gt;getValue('numColumns');
    $numColumns += 1;
    $form_state-&gt;setValue('numColumns', $numColumns);
    $form_state-&gt;setRebuild(TRUE);


in addColumnSubmit()
Assuming all your logic for $form[‘column’][$i] is correct, you can try replacing '#attributes'

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


With '#prefix' and '#suffix'

$form['column_wrapper'] = array(
        '#type'       =&gt; 'container',
        '#prefix' =&gt; '&lt;div id="column_wrapper"&gt;',
        '#suffix' =&gt; '&lt;/div&gt;',
    );


And then in the callback get the values from the complete form. 

public function addColumnCallback(array $form, FormStateInterface &amp;$form_state) {
    $form = $form_state-&gt;getCompleteForm();
    return $form['column'];
}


I had a similar problem, Ajax does rebuild the form, but using “old” values, so after the $form[‘column’][$i] is completed and calculated, Ajax then just overrides it with the previous $form[‘column’][$i]. 
If that makes sense.