Score:1

Refresh a form with Ajax after closing a Dialog

mx flag
JFK

So I have a custom form in which I display a list of entities. Below that list, I added an “Add More” link which opens a Dialog. When I close (or submit) the Dialog, I want the list of entities to be updated dynamically without refresh.

enter image description here

I looked but I can't find a way to add a Dialog callback function. So I added an "update" button in my custom form with an ajax callback to refresh the form. Then, in a javascript file, I trigger the update button when the event 'dialog:afterclose' occures.

  Drupal.behaviors.addFriend_modalcallback = {
    attach: function () {

      $(window).once('addfriend-modalcallback').on('dialog:afterclose', function (e) {

        $('input[data-drupal-selector="edit-update"]').trigger('mousedown');

      });

    }
  };

This is obviously a messy solution. Do you guys know a clean way to do this? Thanks!

us flag
While this might be messy, but it's the only solution I know about, apart from reloading the page, which brings other issues.
I sit in a Tesla and translated this thread with Ai:

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.