I discovered today (after much headdesking...) that when you have several AJAX buttons in a form, FormAPI figures out which one you clicked based on two things:

- the #name property of the button
- the #value property of the button, which is its visible text.

Because the #name properly isn't usually explicitly set (I don't think there's documentation that tells you why you ought to set it), it gets set by FormAPI to 'op'.

This means that if you have two AJAX buttons, with the same label, FormAPI will always think you clicked the first one. (The code for this is in elementTriggeredScriptedSubmission())

In light of this, I think there should be a second AJAX FormAPI example, which is an expanded version of AjaxAddMore, with two 'Add one more' buttons -- say one for picnic guests, and one for picnic shopping list items?

This should be a separate example rather than expanding the existing AjaxAddMore form, as AJAX is complicated, and the simple example should be as simple as possible.

Comments

joachim created an issue.