I'm triggering an ajax-enabled button on a form but Drupal's setting
$form_state['#triggering_element'] to the wrong element.
The button is a child of a
#tree and is identical to other buttons in other tree-ed structures, except for its parents. But I thought this was the point of
Looking at the drupal code in
form.inc it's clear that Drupal only goes on the
#name property to identify the triggering element, which is automatically set to
'op' for buttons. This seems to have no idea about trees or the element's parents.
The rather scant and very old docs for tree state:
#parentsis used to create the name/ID of the form element itself.
But my button element's names are not being set to anything other than 'op'. I'm creating the buttons in a
#process function for the parent element.
$form['group1'] = [ '#prefix' => '<div>group1', '#suffix' => '</div>', '#tree' => TRUE, 'trig' => [ '#type' => 'submit', '#value' => 'ajax go', '#ajax' => [ 'callback' => 'mymod_ajax_callback', 'wrapper' => 'foo', ], // Other elements part of group 1... ], $form['group2'] = // The same.
A work-around is to code creating unique names for every one of these elements, but I feel I might be missing a trick/nuance?