Alter existing form and add element with an ajax "add more" button I am altering the field settigns form, in order to add custom settings. I used the example module as a guide and added my code in the following manner:

/**
 * Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
 */
function fd_image_form_field_config_edit_form_alter(array &amp;$form, FormStateInterface $form_state) {


  // Gather the number of names in the form already.
  $num_names = $form_state-&gt;get('num_names');
  // We have to ensure that there is at least one name field.
  if ($num_names === NULL) {
    $name_field = $form_state-&gt;set('num_names', 1);
    $num_names = 1;
  }

  $form['#tree'] = TRUE;
  $form['names_fieldset'] = [
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('People coming to picnic'),
    '#prefix' =&gt; '&lt;div id="names-fieldset-wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
  ];

  for ($i = 0; $i &lt; $num_names; $i++) {
    $form['names_fieldset']['name'][$i] = [
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('Name'),
    ];
  }

  $form['names_fieldset']['actions'] = [
    '#type' =&gt; 'actions',
  ];
  $form['names_fieldset']['actions']['add_name'] = [
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Add one more'),
    '#submit' =&gt; ['_fd_image_add_one'],
    '#ajax' =&gt; [
      'callback' =&gt; '_fd_image_add_more_callback',
      'wrapper' =&gt; 'names-fieldset-wrapper',
    ],
  ];
  // If there is more than one name, add the remove button.
  if ($num_names &gt;= 1) {
    $form['names_fieldset']['actions']['remove_name'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Remove one'),
      '#submit' =&gt; ['_fd_image_remove_callback'],
      '#ajax' =&gt; [
        'callback' =&gt; '_fd_image_add_more_callback',
        'wrapper' =&gt; 'names-fieldset-wrapper',
      ],
    ];

    $form_state-&gt;setCached(FALSE);
  }
}


I also added my ajax callbacks:

/**
 * Callback for both ajax-enabled buttons.
 *
 * Selects and returns the fieldset with the names in it.
 */
function _fd_image_add_more_callback(array &amp;$form, FormStateInterface $form_state) {
  return $form['names_fieldset'];
}

/**
 * Submit handler for the "add-one-more" button.
 *
 * Increments the max counter and causes a rebuild.
 */
function _fd_image_add_one(array &amp;$form, FormStateInterface $form_state) {
  $name_field = $form_state-&gt;get('num_names');
  $add_button = $name_field + 1;
  $form_state-&gt;set('num_names', $add_button);
  // Since our buildForm() method relies on the value of 'num_names' to
  // generate 'name' form elements, we have to tell the form to rebuild. If we
  // don't do this, the form builder will not call buildForm().
  $form_state-&gt;setRebuild();
}

/**
 * Submit handler for the "remove one" button.
 *
 * Decrements the max counter and causes a form rebuild.
 */
function _fd_image_remove_callback(array &amp;$form, FormStateInterface $form_state) {
  $name_field = $form_state-&gt;get('num_names');
  if ($name_field &gt; 1) {
    $remove_button = $name_field - 1;
    $form_state-&gt;set('num_names', $remove_button);
  }
  // Since our buildForm() method relies on the value of 'num_names' to
  // generate 'name' form elements, we have to tell the form to rebuild. If we
  // don't do this, the form builder will not call buildForm().
  $form_state-&gt;setRebuild();
}


Now when I go to the field settings form, I see my form elements and I do see the add more button. I can click the add more button 1 time and it adds an extra element, but the problem is, I cannot add more than 2. Once the page have 2 elements subsequents clicks on "add more" result in an ajax callback that does nothing.      

After debugging it looks like the $num_names is not being correctly stored and increased. I am assuming that is because the Examples module has it's own buildFrom method while in my case I am only altering. What is the correct way of adding an ajax element to an existing form?
Answering my own question after resolving the issue. 
Removing $form_state-&gt;setCached(FALSE); fixed the issue.   

However, I am not sure why it did or whether this have negative consequences. Hope this helps others.