In subform_wrapper_after_build() there is a code that allows implementing modules to set the triggering element manually. However it doesn't work, as we need to set also the $form_state, not only the $subform_state.
Also when we try to get the nested value, we should do it from the $form_state and not the $subform_state.
Current patch fixed that.
To test, you can use user-modal (in my sandox) and try in FF to login using the Enter key. User modal, makes sure the triggering element is the current tab the user is watching.
Comments
Comment #1
casey commentedHmm the whole pattern is a bit flawed. What if you have multiple subforms that all need a different triggering element? Then #subform_triggering_element wouldn't be sufficient.
Maybe we should just drop #subform_triggering_element. If you want manually set a triggering element you could just add an #process handler for that, in which you call subform_set_triggering_element().
The subform_set_triggering_element() function is however fine. We just needed to pass the $subform_state instead of the $form_state.
Comment #2
amitaibuHere's another stab:
1) Removed the flawed code.
2) Changed signature of
subform_set_triggering_element()to include $subform_name.3)
subform_set_triggering_element()Set the triggering element also on the $form_state, as it is later required in subform_element_submit() (and documented that).4) Not sure about it -- I have removed the part where we set the
$subform_state[$type . '_handlers']. Otherwise in user_modal_subform_after_build() when I callsubform_set_triggering_element()it results we the submit handler beingsubform_element_submit()instead of the correct one -- probably needs more attention to understand why it was needed in the first place.btw, did you have a chance to install user-modal module? at least for me it provides a good test case for subform -- which I'm soooo happy you wrote ;)
Comment #3
casey commentedOnly dropped #subform_triggering_element.
Looking at user-modal I think you had to set the triggering element of the wrapper form, so you're code has to be something like:
Comment #4
casey commentedAlso added some doc to subform_set_triggering_element().
Comment #5
casey commentedReintroduced #subform_triggering_element. See module page for docs.
Comment #6
casey commentedI think you should change it to just setting the $form_state['triggering_element']. I am thinking of dropping subform_set_triggering_element().
Comment #7
casey commentedOk I keep subform_set_triggering_element() for now, but it should only be used on subforms. Also added some extra doc.