API page: http://api.drupal.org/api/drupal/includes--ajax.inc/function/ajax_comman...
Describe the problem you have found:
It states that $selector A jQuery selector string. If the command is a response to a request from an #ajax form element then this value can be NULL. I assume this means when you return an array of AJAX commands from a callback called from an #AJAX form element that the selector is automatically set to the wrapper or the element that called the request. However if I do set this parameter to NULL then nothing happens.
When debugging the situation it looks like on line 580 of misc/ajax.js the response.selector is NULL. If I add a parameter then it works as expected.
Is this the desired outcome? Maybe you're not meant to call the AJAX commands through a callback function when using Form API but I can't see anything else in the documentation to call an AJAX command without returning an array of them via a callback.
Comment | File | Size | Author |
---|---|---|---|
#14 | patch_commit_7ab945d0d1f3.patch | 2.75 KB | jdelaune |
#9 | patch_commit_1f078d8a375b.patch | 2.74 KB | jdelaune |
#8 | ajax.patch | 2.75 KB | jdelaune |
Comments
Comment #1
jhodgdonGood question. We should probably get someone who knows about the AJAX framework to answer it.
So although this is likely a documentation issue, I'm moving it in to the ajax system component to see if we can get an answer.
Comment #2
rfayThe case of $selector == NULL is where we're using the 'wrapper' portion of #ajax to determine the selector. In other words, if the selector is null, assume we're in the middle of #ajax operation and know that the selector is the one determined by '#ajax'['wrapper'].
If you're returning an array of AJAX commands, you're already overriding that behavior.
I'm not entirely sure I understand what you're trying to accomplish, but essentially: you probably won't use the NULL situation if you're working with AJAX commands.
Comment #3
jhodgdonSo rfay does the documentation need an update here or is this a support request only?
Comment #4
jdelaune CreditAttribution: jdelaune commentedThanks guys.
rfay, I am passing a #wrapper paramater on the Form API element where the #ajax callback is made from. How would one call an AJAX Command straight from a Form API element without providing a #ajax callback parameter? I can't see to see it documented anywhere.
For an example:
Thanks in advance
Comment #5
jdelaune CreditAttribution: jdelaune commentedAfter some more testing it seems to be based on the ajax command you are using on whether or not it will work.
e.g. ajax_command_append() and ajax_command_insert() seem to work when you set the selector to NULL. But other commands like ajax_command_css() and ajax_command_invoke() don't work, you need to specify a selector.
Is this expected?
Comment #6
jdelaune CreditAttribution: jdelaune commentedI think I have found the bug, not maybe it's not a bug it's working as you expect.
Here's the 'patched' misc/ajax.js function (line 576)
Simply if you don't supply a selector then it will fall back and use the wrapper?
Works a treat for what I want.
Comment #7
rfayIMO they should all behave the same. I probably can't look at this in the next week, but could you post a patch that makes it behave predictably?
Thanks,
-Randy
Comment #8
jdelaune CreditAttribution: jdelaune commentedThis lets you set the selector parameter to NULL on all AJAX commands, if NULL then it will default to the wrapper as specified, if available.
Results tie in to what the documentation states should happen.
Comment #9
jdelaune CreditAttribution: jdelaune commentedHmm lets see if the test bot like this one better...
Comment #10
jhodgdonYou need to set the issue status to "needs review" for the test bot to review it. :)
Comment #11
jdelaune CreditAttribution: jdelaune commentedThanks for the tip. So what's the next stage if the test bot likes it?
Comment #12
jhodgdonThe next step is for people to review the patch.
Comment #13
rfayAnd unfortunately the next step is to get it into 8.x first.
Comment #14
jdelaune CreditAttribution: jdelaune commentedWell I'll continue to hoop jump...
This one is made against the 8.x branch
Comment #15
klonos...bump.
Comment #18
Wim LeersNo longer relevant for D8.