0

I have a node type with a multivalue filefield. I am using some jquery called by my custom module to modify some of the UI in the form, but when I click the "Add Another Item" button it completely breaks and wipes out my custom external jquery. How can I fix this?

1

These tips are correct for Drupal 7.
Your custom code should be coordinated with Drupal AJAX Framework.
When you click "Add Another Item" this happens:

  1. AJAX handler sends all the form with all values, and with point to element which has triggered AJAX.
  2. Server returns fully new field. For example, if there were 4 inputs in your field, server will return 5 inputs, not just last fifth.
  3. After that new piece of HTML goes through all the behaviors. As you may know, behavior's attach method has two params: context and settings. context is just new HTML for your field.

So, if you add your JS to this schema correctly it must work.

Drupal.behaviors.YOURMODULE = {
  attach: function (context, settings) {
    $('.some-class', context).once('YOURMODULE', function() {
      // Do some work here
    });
  }
}
  • I accepted your answer because it pointed my in the right direction...I'm on Drupal 6 – user2014 Sep 15 '11 at 17:49
  • So you can use tags 6 and 7 to point your Drupal version. – kalabro Sep 16 '11 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy