Skip to content

Instantly share code, notes, and snippets.

@devudit
Created November 27, 2017 12:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devudit/dcdb76502975a13dd7c623cecc04f509 to your computer and use it in GitHub Desktop.
Save devudit/dcdb76502975a13dd7c623cecc04f509 to your computer and use it in GitHub Desktop.
Create modal window in drupal 8 using Drupal.dialog function
/** EXAMPLE 1 ***/
var $myDialog = $('<div>My dialog text</div>').appendTo('body');
Drupal.dialog($myDialog, {
title: 'A title',
buttons: [{
text: 'Close',
click: function() {
$(this).dialog('close');
}
}]
}).showModal();
/** EXAMPLE WITH AJAX **/
Drupal.ajax({
url: 'some/path',
success: function(response) {
var $myDialog = $('<div>' + response.data + '</div>').appendTo('body');
Drupal.dialog($myDialog, {title: 'Some title'}).showModal();
}
}).execute();
@tbisciglia
Copy link

This is brilliant. So clear and easy to follow. No more ugly Javascript popups!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment