Ajax on Add another item of field collection

by sneha.kamble   Last Updated January 14, 2018 11:07 AM

I'm calling an Ajax function in a field collection. But after hitting 'Add another item' button, form looses Ajax effect. I want to bind the Ajax with form event after clicking on 'Add another item' button. Can anyone help?

Answers 2

Sounds like you need to use Drupal.behaviors and not just document.ready for your javascript.

Drupal uses a "behaviors" system to provide a single mechanism for attaching JavaScript functionality to elements on a page. The benefit of having a single place for the behaviors is that they can be applied consistently when the page is first loaded and then when new content is added during AHAH/AJAX requests.

More info on Drupal.behaviors here

David Thomas
David Thomas
January 02, 2013 10:04 AM

Actually on reload of page Ajax looses its effect. So we solved this problem through form alter.

$form['#after_build'] gives us all the detail after save so that helps to retrieve values again and filter.

February 15, 2013 06:36 AM

Related Questions

How to nest a field collection d8

Updated December 11, 2017 14:07 PM

Sum value from outside field collection

Updated January 01, 2018 19:07 PM