Drupal nested ajax call not working correctly
Correct one, just copy and paste it:

function agl_jira_new_test_form($form, &amp;$form_state) {
  $form['#tree'] = TRUE;
  $form['select'] = array(
    '#title' =&gt; 'select',
    '#type' =&gt; 'select',
    '#options' =&gt; drupal_map_assoc(array('man', 'woman')),
    '#required' =&gt; TRUE,
    '#default_value' =&gt; isset($form_state['values']['select']) ? $form_state['values']['select'] : 'man',
    '#ajax' =&gt; array(
      'callback' =&gt; 'agl_jira_select_callback',
      'wrapper' =&gt; 'names-fieldset-wrapper',
    ),
  );
  $form['test']['names_fieldset'] = array(
    '#type' =&gt; 'fieldset',
    '#prefix' =&gt; '&lt;div id="names-fieldset-wrapper"&gt;',
    '#suffix' =&gt; '&lt;/div&gt;',
    '#tree' =&gt; TRUE,
  );
  if (isset($form_state['values']['select']) &amp;&amp; $form_state['values']['select'] == 'man') {
    $form['test']['names_fieldset']['text'] = array(
      '#title' =&gt; t('name'),
      '#type' =&gt; 'textfield',
    );
    $form['test']['names_fieldset']['attachment'] = array(
      '#title' =&gt; t('File'),
      '#type' =&gt; 'fieldset',
      '#prefix' =&gt; '&lt;div id="agl-jira-file-attach-wrapper"&gt;',
      '#suffix' =&gt; '&lt;/div&gt;',
      '#tree' =&gt; TRUE,
    );
    if (!isset($form_state['num_names'])) {
      $form_state['num_names'] = 1;
    }
    for ($i = 0; $i &lt; $form_state['num_names']; $i++) {
      $form['test']['names_fieldset']['attachment'][$i] = array(
        '#type' =&gt; 'managed_file',
        '#title' =&gt; t('Name'),
      );
    }
    $form['test']['names_fieldset']['add_name'] = array(
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Add one more'),
      '#submit' =&gt; array('agl_jira_example_add_more_add_one'),
      '#ajax' =&gt; array(
        'callback' =&gt; 'agl_jira_example_add_more_callback',
        'wrapper' =&gt; 'agl-jira-file-attach-wrapper',
      ),
    );
  }
  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; 'submit',
  );
  return $form;
}

function agl_jira_select_callback($form, &amp;$form_state) {
  $form_state['rebuild'] = TRUE;
  return $form['test']['names_fieldset'];
}

function agl_jira_example_add_more_callback($form, &amp;$form_state) {
  return $form['test']['names_fieldset']['attachment'];
}

function agl_jira_example_add_more_add_one($form, &amp;$form_state) {
  $form_state['num_names']++;
  $form_state['rebuild'] = TRUE;
}

function agl_jira_new_test_form_submit($form, &amp;$form_state) {
  $form_state['rebuild'] = TRUE;
}


removed $form['test']['names_fieldset'] = array(
    '#markup' =&gt; '&lt;div id="names-fieldset-wrapper"&gt;&lt;/div&gt;',
  );, added reference to the form_state in agl_jira_example_add_more_callback..