This request comes after some comments in the Randy Fay blog http://randyfay.com/node/74
Is there any way to pass the "triggering element" with an AJAX link?
An example of AJAX link can be seen here:
http://api.drupal.org/api/examples/ajax_example--ajax_example_misc.inc/7...
In action (demo) here:
http://d7.drupalexamples.info/examples/ajax_example/ajax_link
In the source code you can see that the only parameter that you receive in the callback is $type = 'ajax' or 'nojs' (thanks to the menu)
Do you have any idea how to receive the triggering element? Or the only way is using Drupal Forms API?
I think the AJAX Link will be so much powerful if you know what triggered the action. Think about tables or lists of data with ajax 'delete' links for example or 'bookmark' links, etc. all of these links with a generic callback function.
Thanks
Comments
Comment #1
rfayI'm thinking that there isn't, since there is no "element". The triggering element is the link. If you're executing link code and $type == 'ajax', the link triggered it. Maybe I'm missing the point?
Comment #2
corbacho commentedRandy, but if you have several links with the same ajax callback.. how do you know which of these links was clicked? (so in the ajax callback you can for example "Delete from database the element that was clicked").
I think it's not possible. The work-around is to make a "submit" form element with #ajax property and change with css how it looks to make it appear as a link, (or the way you want)
Comment #3
sinasalek commentedPossible work around #1681354: Pass arguments using ajax and link element
Also each element can be given an html id using drupal_html_id and that id can be passed as callback url argument
either way it has be handled manually.
It might be possible to modify Drupal ajax js to pass this parameter but that requires core patch
Comment #4
jungleNo activity for over 10 years. I am closing this. Please feel free to reopen if necessary.
Thanks!