Compatibility with Drupal.attachBehaviors
markus_petrux - January 24, 2009 - 05:13
| Project: | Views Bulk Operations (VBO) |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | bug report |
| Priority: | normal |
| Assigned: | kratib |
| Status: | closed |
Jump to:
Description
When views form is loaded dynamically using AHAH/AJAX the Views Bulk Operations behavior is broken.
To fix this, vbo would have to implement its startup code using Drupal.behaviors rather than if (Drupal.jsEnabled) { jQuery(document).ready(function() { .... See misc/textarea.js for an example. Then, it may not need to invoke the startup code from ajaxViewResponse() as I believe this would be done already by Drupal.Views.Ajax.ajaxViewResponse() in views/js/ajax_views.js. If not, then you may probably invoke that from your ajaxViewResponse() implementation.

#1
I was expecting this. But can you explain what is currently broken with AHAH? I've tried Views with Ajax on and things seemed to be working properly.
#2
I came here due to a problem in editablefields module: #359435: Editablefields will not work if Views Bulk Operations is also active
Note that any module can implement AHAH/AJAX stuff in views that causes to rebuild part of the DOM in the document, and that part may affect the whole view, hence that AHAH/AJAX code would need a method to attach behaviors to the new DOM elements. Thid is explained better on top of misc/drupal.js in 6.9:
/*** Attach all registered behaviors to a page element.
*
* Behaviors are event-triggered actions that attach to page elements, enhancing
* default non-Javascript UIs. Behaviors are registered in the Drupal.behaviors
* object as follows:
* @code
* Drupal.behaviors.behaviorName = function () {
* ...
* };
* @endcode
*
* Drupal.attachBehaviors is added below to the jQuery ready event and so
* runs on initial page load. Developers implementing AHAH/AJAX in their
* solutions should also call this function after new page content has been
* loaded, feeding in an element to be processed, in order to attach all
* behaviors to the new content.
*
* Behaviors should use a class in the form behaviorName-processed to ensure
* the behavior is attached only once to a given element. (Doing so enables
* the reprocessing of given elements, which may be needed on occasion despite
* the ability to limit behavior attachment to a particular element.)
*
* @param context
* An element to attach behaviors to. If none is given, the document element
* is used.
*/
Drupal.attachBehaviors = function(context) {
context = context || document;
if (Drupal.jsEnabled) {
// Execute all of them.
jQuery.each(Drupal.behaviors, function() {
this(context);
});
}
};
If VBO doesn't provide a Drupal.behaviors implementation, then other modules have no method to attach your behaviors to the new DOM elements that they may have loaded, and that can include the whole view, or part of it. Hence other modules doing AHA/AJAX in views will brake VBO.
#3
In #2 I forgot to mention that Drupal.vbo.ajaxViewResponse() would have to call Drupal.attachBehaviors(), maybe it could simply do as Drupal.Views.Ajax.ajaxViewResponse() in views/js/ajax_views.js. That way editablefields would have the oportunity to attach its own behaviors to the new DOM elements loaded by VBO's ajax feature.
#4
I checked in a fix in the latest dev. Please pull from CVS (DRUPAL-6--1 branch) or wait 12 hours before Drupal.org refreshes the release. The nice thing is that by declaring Drupal.behaviors.vbo, I was able to eliminate the whole ajaxViewResponse() hack altogether!
#5
Fixed unless anyone says otherwise.
#6
Yep: scmizer confirmed it works here:
http://drupal.org/node/359435#comment-1231352
Thank you! :)
#7
Automatically closed -- issue fixed for 2 weeks with no activity.