Using AJAX in blockform I'm attempting to allow a user to add text fields by clicking a button in a configuration form for a block plugin. I'm currently populating the form like so:

public function blockForm($form, FormStateInterface $form_state) {
    for ($i = 0; $i &lt; $this-&gt;configuration['linkNum_submit']; $i += 1) {
        $form['link'][$i] = array(
            '#type'          =&gt; 'textfield',
            '#title'         =&gt; 'Link',
            '#default_value' =&gt; '',
        );
    }


My form is populated using a for loop that takes into account a configuration field noting the amount of textfields that should be displayed.

I also have a button that's meant to add another $form['link'] textfield by doing an ajax callback.

$form['add_link'] = array(
    '#type'     =&gt; 'button',
    '#value'    =&gt; $this-&gt;t('Add link'),
    '#ajax'     =&gt; [
        'callback' =&gt; array($this, 'Drupal\my_module\Plugin\Block\LinkList::addLink'),
        'event'    =&gt; 'click',
        'progress' =&gt; array(
            'type'    =&gt; 'throbber',
            'message' =&gt; t('Adding link...'),
        ),
    ],
);


Below is the ajax function that is called. It attempts to increase the configuration field the for loop in bockForm is based on.

public function addlink(array&amp;$form, FormStateInterface $form_state) {
    $response = new AjaxResponse();
    $this-&gt;configuration['linkNum_submit'] += 1;

    return $response;
}


I believe my issue is that the form isn't being rebuilt, but I'm not sure how to force it to. I found documentation on the rebiuldForm() function here https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilder.php/function/FormBuilder%3A%3ArebuildForm/8.2.x but I'm not sure how to implement it in this case.
The issue is not about the form rebuild, the form is being automatically rebuilt on every AJAX call.
The issue here is of the wrapper is not being defined in the '#ajax' array and the wrapper attribute should be given to a "container" type of field and then all of the updated fields should be part of the respective "container" field.

or some ajax command should be called on $response object in the ajax callback method above. 

e.g. 

public function blockForm($form, FormStateInterface $form_state) {

$form['link'] = array(
  '#type' =&gt; 'container',
  '#attributes' =&gt; array('id' =&gt; 'link-wrapper'),
);
for ($i = 0; $i &lt; $this-&gt;configuration['linkNum_submit']; $i += 1) {
    $form['link'][$i] = array(
        '#type'          =&gt; 'textfield',
        '#title'         =&gt; 'Link',
        '#default_value' =&gt; '',
    );
$form['add_link'] = array(
  '#type'     =&gt; 'button',
  '#value'    =&gt; $this-&gt;t('Add link'),
  '#ajax'     =&gt; [
    'callback' =&gt; array($this, 'addLink'),
    'event'    =&gt; 'click',
    'wrapper' =&gt; 'link-wrapper',
    'progress' =&gt; array(
        'type'    =&gt; 'throbber',
        'message' =&gt; t('Adding link...'),
    ),
],


);

and then in the ajax callback

public function addlink(array&amp;$form, FormStateInterface $form_state) {
  return $form['flipper']['front']['settings']['link'];
}