Hi there,
I'm trying to use AJAX to dynamically update the default value of a dependency-driven form inside of a CTools/Panels custom content type (Apologies if this is more of a Panels issue) and am just failing to get anywhere.
In order to troubleshoot this, I've essentially removed all my code in hook_content_type_edit_form() and replaced it with the basic form API AJAX example code at http://drupal.org/node/752056
I've also posted a question on drupal.SE -- http://drupal.stackexchange.com/questions/39818/ajax-calls-in-ctools-con...
It seems that the callbacks are just refusing to fire -- I've put a watchdog call in my callback and nothing's in dblog.
I've been working with no less than two other people who are having difficulty with this and it seems there's not a lot of documentation about using AJAX in a Panels custom content type. We're almost at a point where we don't think CTools content type edit forms can do AJAX -- but surely this isn't the case?
If it is -- any suggestions how to use form dependencies to set default values? My code drops in a pane that lets the user choose one of three different link types in the edit form, which show/hide different options based on which is selected (a la dependencies). One of these options is the link target -- it'd be great to be able to set _blank as the default select option for external links and _self for internal.
Any help you can give on this would be most appreciated -- we're all kinda losing hair and sleep over here about this.
Thanks!
Comments
Comment #1
anandkp commentedHey there aendrew!
I've been stuck on the exact same problem for the last two days and can't figure out for the life of me how to get past this roadblock. I actually stumbled upon your thread on SE yesterday while looking for a solution. I see that one of the answers mentions the use of hook_menu() and providing a path to call... which I've experimented with but can't get past.
The last comment on your SE thread is sorta the same with what I'm left wondering - after declaring a path to for $form['select_item']['#ajax]['path'], I'm stumped as to what I should do in the page callback.
The following is a snippet of the code I'm working on:
Any help you could give would be so very, very much appreciated!
I wish that there was more documentation on #ajax for ctools forms or better yet, that ctools implemented form ajax in a way that simply using Drupal 7 native $form['select_item']['#ajax]['callback'] would work as expected...
Thanks in advance!
Comment #2
rafalenden commentedSee Contextual Entity list module.
Comment #3
aendra commented@rafal.enden -- I'm a bit confused; mind expanding on that? I don't see how that allows arbitrary JavaScript to be used with Panels content types (Though it does look interesting, might check it out in a bit).
Comment #4
rafalenden commentedAuthor of Contextual Entity list module created menu callback to execute AJAX call through pane edit form.
Comment #5
hefox commentedI think I got something similair working in latest patch in #2017159: Panopoly Magic: render preview outside of pane configuration form
Comment #6
alcroito commentedI've had a similar problem, where I wanted to include a Media element type into a CTools content type plugin, that also uses ajax for selecting an image.
It uses it's own ajax 'path' setting, instead of the 'callback' setting, but when selecting an image, the form was rebuilt without the media element entirely.
I traced this to the fact that drupal_rebuild_form couldn't find neither the CTools form wrapper function, nor the actual settings form function. So I fixed it by adding these lines of code to the ctools settings form:
Maybe I'm missing something obvious why the include files are not loaded, but including them manually fixed the issue for me.
Comment #7
hamrant commentedThank you, Placinta, #6 helped me a lot.
In my form I put:
And this fixed ajax error.
Comment #8
capynet commented#6 Fixed my need: Use ajax dependent fapi element on the ctool content_type settings form.
Comment #9
tom_ek commentedJust wanted to confirm that #6 fixes the issue. Indeed using ajax calls inside of the Custom Panes causes the form to be rendered without any custom-defined fields.
Comment #10
mustanggb commented