Score:0

Load view form with ajax missing ajax functionality

us flag

When clicking an element I get a form which is generated by a view (using https://www.drupal.org/project/editablefields module). The problem is that the ajax functionality of the form is lost (no ajax-processed classes are present). This is the working js code to retrieve the view:

(function($,Drupal) {
  Drupal.behaviors.MODULE = {
    attach:function (context, settings) {   
      $('#test').click(function () {
        var args = (1, 2, 3);
        
        $.ajax({
          url: Drupal.settings.basePath + 'views/ajax',
          type: 'post',
          data: {
            view_name: 'test_view',
            view_display_id: 'block',
            view_args: args,
          },
          dataType: 'json',
          success: function (response) {
            if (response[1] !== undefined) {    
              var viewHtml = response[1].data;
              $('#form_test').html(viewHtml);
              Drupal.attachBehaviors();  
            }
          }
        });
      });
    }
  }
  
}(jQuery, Drupal));

So my question is how to get ajax working again on the form? Do I have to call ajax_pre_render_element and if so in which PHP function?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.