I created a custom field. The hook_field_widget_form has an submit element with an ajax callback:
//Add more
$element['add_zone'] = array(
'#type' => 'submit',
'#name' => $field_name . '-add_more-' .'name',
'#value' => t('+'),
'#limit_validation_errors' => array(),
'#submit' => array('dms_polygone_add_more_add_one'),
'#ajax' => array(
'callback' => 'dms_polygone_add_more_callback',
'wrapper' => 'zones-fieldset-wrapper-'. $field_name,
),
);
I add 2 fields of my custom field type to a node. Ex: field_polygone (field type: polygone) and field_polygone_2 (field type: polygone). When i press the 'add_more' button of my first field_polygone, my callback function 'dms_polygone_add_more_add_one' thinks the trigger element is field_polygone_2.
Callback function:
function dms_polygone_add_more_callback($form, $form_state) {
//@todo: $i gebruiken voor veld als er meerdere waardes zijn toegestaan.
$parents = $form_state['triggering_element']['#parents'];
return $form[$parents[0]][$parents[1]][$parents[2]]['zones'];
}
$parents[0] is the field_name => When i press 'add_more' , the $parents[0] variable in the callback function should be 'field_polygone', but its field 'field_polygone_2'.
How can is solve this problem? Why does the callback function think the trigger element is field_polygone_2 instead of field_polygone.