In case one adds css or js files via the #attached property, it won't work when the array is rendered during an ajax callback. That way the files are never added.
Steps to reproduce:
* Do a simple form without any fieldsets on the page.
* Add an ajax callback and add collapsed fieldset to the returned structure.
-> Collapse.js won't get loaded, thus you are unable to open the fieldset.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | ajax_bug_demos.tgz | 1.78 KB | rfay |
Comments
Comment #1
rfaysubscribe. You sure know how to find them!
Comment #2
yhager commentedThis is quite troubling. I am trying to build an ajax element that requires dynamic js (http://drupal.org/project/imagefield_crop), and I have no way to implement that without being able to add dynamic js settings.
I've also tried calling plain old drupal_add_js() in the process function, but that doesn't seem to work as well.
Even a workaround until this is properly fixed would be appreciated.
Comment #3
yhager commentedThanks @merlinofchaos for pointing me to #561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework which blocks this.
Comment #4
dmitrig01 commentedComment #5
yhager commentedSetting to critical based on the discussion in #561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework. Not sure why you are marking this as postponed, as it clearly does not work as intended.
Comment #6
dmitrig01 commentedPostponed = waiting on something else. It's postponed until the other issue is fixed.
Comment #7
yhager commentedThat is called "blocked" in other issue management systems.
Comment #8
rfayIt should be active for our purposes here, so it doesn't go off the radar. I think we use "postponed" only when a decision has been made not to do it for the foreseeable future.
Blocked for now by #561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework. Taking this one out of "critical" though - although I think the case can be made that that one is critical, it would have to be made here for this one.
Comment #9
rfayAttached is a bug demo module that demonstrates the exact description by fago. Use the "AJAX bugs: AJAX adds fieldset" menu item.
Marked #810578: #collapsible not working for elements rendered via AJAX as a duplicate of this one.
Comment #10
yched commentedAlso forbids #states in ajax updated parts of forms - which is sad :-).
Comment #11
effulgentsia commentedI believe this is a straight up duplicate of #561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework. That's the issue that's dealing with the problem that calls to drupal_add_(css|js)() don't result in CSS/JS being added during an AJAX response. When that's fixed, this issue's problem will be fixed too, as #attached does correctly call drupal_add_*().
Comment #12
rfay#561858-78: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework now has a patch from merlinofchaos that gives us lazy loading and makes #attached and #states work. Please go over there and review/improve it.
Comment #13
yched commented#561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework got in, but ['#attached']['js'] or drupal_add_js() still fail to add new scripts to the page when executed in an ajax callback.
(js settings are correctly merged though)
Comment #14
yched commentedRe: myself in previous comment:
Never mind. #1962236-4: Scripts added using drupal_add_js() are never added to the page after an AJAX callback from @Wim Leers explains that this is a weirdness in jQuery <=1.9 that the scripts do not appear to be added to the DOM, but they are still correctly loaded.
Bumping jQ to 1.10 with latest release of jquery_update fixes the weirdness (the additional
<script>tags do appear in the DOM)