0

I'm loading a form using AJAX commands. However, it seems to me that forms loaded with AJAX can't submit using AJAX.

This is what i do :

  1. Load a form through an ajaxified link. The link invokes a path which maps to a callback function responsible for returning an ajax commands array. This works fine, and the form is loaded onto the page just where it should be.
  2. I go through the form, and click on submit. The form the submits the page, and the form appears to not have been ajaxified at all.

There is one thing that i suspect may be part of the trouble. It seems to me that not all required JS files are loaded after the commands array have updated the page with the form.

In other words, the number of JS files are not the same if i show the form directly and if i load the form using ajax. If i show the form directly, then the form gets perfectly ajaxfied, whereas if i load the form using ajax it does not get ajaxified.

I've had a look at the Drupal examples module, but haven't found an example which demonstrates this particular case.

Any ideas?

  • 1
    This is a common problem...you attach the events to the form on page load, then re-load part of the page with ajax, at which point the events you attached originally have disappeared (because the original HTML elements have replaced). The standard jQuery solution is to use live() to bind the events, the standard Drupal solution is to use Drupal.behaviors but without seeing your code it's difficult to advise – Clive Jul 18 '12 at 12:44
  • Hi, it appeared to be related to a custom AJAX command of mine. I hadn't invoked Drupal.attachBehaviours from my command function on client/JS side...thus not attaching AJAX functionality to the form. I fixed it, and it works. Thanks for your help though...post your comment as an answer and I'll accept it. – sbrattla Jul 18 '12 at 14:31

Your Answer

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

Browse other questions tagged or ask your own question.