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.

CommentFileSizeAuthor
#9 ajax_bug_demos.tgz1.78 KBrfay

Comments

rfay’s picture

subscribe. You sure know how to find them!

yhager’s picture

This 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.

yhager’s picture

dmitrig01’s picture

Status: Active » Postponed
yhager’s picture

Priority: Normal » Critical

Setting 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.

dmitrig01’s picture

Postponed = waiting on something else. It's postponed until the other issue is fixed.

yhager’s picture

That is called "blocked" in other issue management systems.

rfay’s picture

Priority: Critical » Normal
Status: Postponed » Active

It 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.

rfay’s picture

StatusFileSize
new1.78 KB

Attached 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.

yched’s picture

Also forbids #states in ajax updated parts of forms - which is sad :-).

effulgentsia’s picture

Status: Active » Closed (duplicate)

I 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_*().

rfay’s picture

#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.

yched’s picture

Issue summary: View changes

#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)

yched’s picture

Re: 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)