I have a fieldset with one field by default. I want to add new fields by ajax (button "new item"). I can do it for usual field, but I have a problem with fieldsets. How to do that?
For usual fields I do it like below:
$form['add_item'] = array(
'#type' => 'button',
'#value' => t('Add item'),
'#ajax' => array(
'wrapper' => 'content',
'callback' => 'add_more_ajax',
'method' => 'append',
'affect' => 'fade',
),
);
function add_more_ajax($form, &$form_state) {
$form['image'] = array(
'#title' => t('Image'),
'#type' => 'managed_file',
'#default_value' => '',
'#upload_location' => 'public://images/',
);
return $form['image'];
}