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?
2 Answers
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
-
thanks for reply...actually while writing my js and ajax i have already used Drupal.behaviors but still its loosing the effect of ajax on page load Jan 2, 2013 at 11:20
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.