1

I have created a custom module with ajax call, which are sending render form data that I receive in my ajax prototype in a js file like below.

Drupal.AjaxCommands.prototype.loadCommentFormCommand = function (ajax, response, status) {
    if ($('#comment-form-wrapper').length === 0) {
        $('.wall-posts').prepend(response.html);
          Drupal.attachBehaviors(response.html);
        }
      };

But it's showing me

context.querySelectorAll is not a function 

Error. Does anyone face similar error or have some solutions for this?

0

1 Answer 1

4

The first argument to Drupal.attachBehaviors is an object representing a DOM element, context. You're currently providing it with a string.

In your case the correct code will probably be something like:

Drupal.attachBehaviors($('#comment-form-wrapper').get(0));

You don't pass data to behaviours through the attachBehaviors method, instead stash it somewhere in a global scope and pick it up later.

For example you might choose the window, drupalSettings, or some other object, depending on your general requirements and any other required uses of that HTML data.

1
  • Hi Clive, Thanks for your quick answer, Let me implement this and will come to you soon.
    – Udit Rawat
    Apr 19, 2018 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.