Download & Extend

Passing triggering element to the ajax callback using an AJAX link

Project:Examples for Developers
Component:AJAX Example
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

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

#1

I'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?

#2

Randy, 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)