Creating a new Form element in ajaxcallback function not affecting form state I am trying to insert new form fields into exiting wrapper within ajax callback function. 

I succeeded doing so, but trying to get those new fields values inside submit function failed because they are listed in the form state values array.

How can I make their values available to be used inside the submit function.

$form['test'] = array(
        '#type' =&gt; 'select',
        '#options' =&gt; array('- Please select -' =&gt; [1=&gt;'one',2=&gt;'two']),
        '#ajax' =&gt; array(
            'callback' =&gt; '::testSelectedCallback',
            'wrapper' =&gt; 'fields-wrapper',
            'effect' =&gt; 'fade',
            'event' =&gt; 'change',
            'progress' =&gt; array(
                'type' =&gt; 'throbber',
                'message' =&gt; NULL,
            ),
        ),
    );
$form['fields-wrapper'] = array(
        '#type' =&gt; 'container',
        '#attributes' =&gt; ['id' =&gt; 'fields-wrapper', 'class' =&gt; ['hiddenselect']],
    );

public function testSelectedCallback(array &amp;$form, FormStateInterface $form_state) {
$form['fields-wrapper']['new_item']= array(
'#type' =&gt; 'textfield',
'#title' =&gt; 'My new item',
);
$form_state-&gt;setRebuild(True);
return $form['new_item'];
}
You cannot add fields in ajax callback functions - assuming that level2SelectedCallback() is your ajax callback (you named it something different in your form element defintion). 

All form elements need to be added in the form definition. The ajax callback is only used for determining which elements need to be inserted into the page when the AJAX is returned.