How to Add more option for type radios use Ajax in Drupal 8 Hi I build Add more for radios  when click button load ajax. This ajax only add more options for radios . But not working , how to build used ajax add more options for type radios form ? Thanks

This code example my demo:

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class DemoForm extends FormBase{

    public function getFormId()
    {
        return 'DemoForm';
    }
    public function buildForm(array $form, FormStateInterface $form_state,$param = array())
    {
        $form['wrapper_data'] = array(
            '#type' =&gt; 'container',
            '#attributes' =&gt; array('id' =&gt; 'wrapper_data'),
        );  
        $form['wrapper_data']['data_media'] = array(
            '#type' =&gt; 'select',
            '#title' =&gt; 'List Media',
            '#options' =&gt; array('aaa','bbb','cccc'), 

        );
        $form['wrapper_data']['load_more_data'] = array(
            '#type' =&gt; 'button',
            '#value' =&gt; 'Load More',
            '#ajax' =&gt; array(
                'callback' =&gt; '::AjaxLoadMore',
                'wrapper' =&gt; 'wrapper_data',
            ),
        );

        return $form;
    }

    public function AjaxLoadMore(array &amp;$form,FormStateInterface $formState){

        $form['data_media']['#options'] += array('bbbb'); // Want Add more options for radios

        return $form['wrapper_data'];
    }
}
Here is the complete code example:

&lt;?php
/**
 * @file
 * File: src/Form/MyExampleForm.php
 * Contains \Drupal\mymodule\Form\MyExampleForm.
 */
namespace Drupal\mymodule\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

class MyExampleForm extends FormBase {

  /**
   * {@inheritdoc}.
   */
  public function getFormId() {
    return 'example_form';
  }

  /**
   * {@inheritdoc}.
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

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

    /* // or:
    $form['wrapper'] = array(
      '#type' =&gt; 'fieldset',
      '#title' =&gt; $this-&gt;t('Example title'),
      '#tree' =&gt; FALSE,
      '#prefix' =&gt; "&lt;div id='data-wrapper'&gt;",
      '#suffix' =&gt; '&lt;/div&gt;',
    );
    */

    /* // or:
    $form['#prefix'] = '&lt;div id="data-wrapper"&gt;';
    $form['#suffix'] = '&lt;/div&gt;';
    */

    $form['wrapper']['data_media'] = array(
        '#type' =&gt; 'radios',
        //'#title' =&gt; 'Title',
        '#options' =&gt; array('aaa','bbb','cccc'), 
        );
    $form['wrapper']['more_data'] = array(
        '#type' =&gt; 'button',
        '#required' =&gt; TRUE,
        '#value' =&gt; 'Show more',
        // @see: https://api.drupal.org/api/drupal/core%21core.api.php/group/ajax/8.3.x
        '#ajax' =&gt; array(
          // The callback to invoke to handle the server side of the Ajax event.
          'callback' =&gt; [$form_state-&gt;getBuildInfo()['callback_object'], 'ajaxLoadMore'],
          // or: //'callback' =&gt; [$this, 'ajaxLoadMore'],
          // or: //'callback' =&gt; '::ajaxLoadMore',
          // @see: http://api.jquery.com/category/manipulation/
          //'method' =&gt; 'replace', // May be: 'replaceWith' (default), 'append', 'prepend', 'before', 'after', or 'html'.
          // The HTML 'id' attribute of the area where the content returned by the callback should be placed.
          'wrapper' =&gt; 'data-wrapper',
          ),
        );
    $form['wrapper']['submit'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; $this-&gt;t('Confirm'),
        );

    return $form;
  }

  /**
   * Ajax handler for loading more radio options.
   */
  public function ajaxLoadMore(array &amp;$form, FormStateInterface $form_state){
    // Add more options for radios.
    $trigger = $form_state-&gt;getTriggeringElement();
    if ($trigger['#value'] == 'Show more') {
      $form['wrapper']['data_media']['#options'] += array_merge($form['wrapper']['data_media']['#options'], ['bbbb']);
    }
    return $form['wrapper'];
  }

  /**
   * {@inheritdoc}
   */
  public function validateForm(array &amp;$form, FormStateInterface $form_state) {
    $values = $form_state-&gt;getValues();
    $trigger = $form_state-&gt;getTriggeringElement();
    if ($trigger['#type'] === 'submit') {
      if (is_null($values['data_media'])) {
        $form_state-&gt;setErrorByName('data_media', t('Please select the option!'));
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    drupal_set_message($this-&gt;t('Your form has been submitted.'));
  }

}