Ajax not working in drupal 8 custom form
<p>I'm trying to use ajax in drupal 8 custom form. But it not work.</p>

<p>I've custom form, in which textfield is display with some value once the user click on the checkbox. Here is my code:-</p>

<pre><code>public function buildForm(array $form, FormStateInterface $form_state) {

$form['del_name'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; $this-&gt;t('Delete users, by name'),
        '#ajax' =&gt; array(
      'callback' =&gt; array($this, 'my_user_callback'),
            'wrapper' =&gt; 'del-name',
        ),
  );

    $form['name_placeholder'] = array(
    '#type' =&gt; 'hidden',
    '#prefix' =&gt; '&lt;div id="del-name"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#tree' =&gt; TRUE,
  );

    if (!empty($form_state-&gt;getValue('del_name')) &amp;&amp; $form_state-&gt;getValue('del_name')) {
   /*
   * $process_data = some stuff
   */   
     $form['name_placeholder']['user_role'] = array(
      '#title' =&gt; $this-&gt;t('Users role'),
      '#type' =&gt; 'textfield',
      '#default_value' =&gt; $process_data
    ); 
  }
}

function my_user_callback(array &amp;$form, FormStateInterface $form_state) {
      return array(
       '#type' =&gt; 'ajax',
       '#commands' =&gt; array(
        ajax_command_replace('#del-name', render($form['name_placeholder'])),
        )
      );
  }
</code></pre>

<p>Problem is that, textfield not appear when checkbox is checked.</p>