How to get my button in a dialog click? I have added the following JS to a node form, it clones the submit button but clicking it inside the dialog (which does show up) doesn't submit the form in the browser, just nothing happens when the button is clicked. I also tried adding the button server side, same results:

(function (window, Drupal, $) {
  Drupal.behaviors.drafter = {
    attach: function attach(context) {
      var button = $('#edit-submit');
      var newbutton = button.clone().prop('id', 'edit-submit-drafter');
      button.click(function () {
        $('#drafter-elements').toggle();
        var confirmationDialog = Drupal.dialog('#drafter-elements', {
          resizable: false,
          closeOnEscape: false,
          create: function () {
            $(this).append(newbutton);
          },
          beforeClose: false,
          close: function (event) {
            $(event.target).remove();
          }
        });
        confirmationDialog.showModal();
        return false;
      })
    }
  }
})(window, Drupal, jQuery);


Where drafter-elements come from:

$form['drafter'] = [
  '#prefix' =&gt; '&lt;div id="drafter-elements"&gt;',
  '#suffix' =&gt; '&lt;/div&gt;',
  '#attached' =&gt; ['library' =&gt; ['drafter/drafter']],
];
$form['drafter']['save_in_place'] = [
  '#title' =&gt; 'Confirm',
  '#type' =&gt; 'checkbox',
  '#description' =&gt; t('By default a new draft will be created.'),
];


With a tiny CSS:

#drafter-elements {
  display: none;
}


(Here's the drafter repository should someone want to try it / fix it.)
for me that submits the node:

(function (window, Drupal, $) {
  Drupal.behaviors.drafter = {
    attach: function attach(context) {
      var button = $('#edit-submit');
      var newbutton = button.clone().prop('id', 'edit-submit-drafter');
      var confirmationDialog = Drupal.dialog('#drafter-elements', {
        resizable: false,
        closeOnEscape: false,
        create: function () {
          $(this).append(newbutton);
        },
        beforeClose: false,
        close: function (event) {
          $(event.target).remove();
        }
      });
      newbutton.click(function (e) {
        button.click();
        confirmationDialog.close();
        return true;
      });
      button.click(function () {
        if (!confirmationDialog.open) {
          confirmationDialog.showModal();
          return false;
        }
      });
    }
  }
})(window, Drupal, jQuery);