Created
November 27, 2017 12:32
-
-
Save devudit/dcdb76502975a13dd7c623cecc04f509 to your computer and use it in GitHub Desktop.
Create modal window in drupal 8 using Drupal.dialog function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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(); |
@ilechcod Yes. This is just how to work with simple HTML snippets.
If you want to do AJAX, you probably want:
https://www.drupal.org/docs/drupal-apis/ajax-api/ajax-dialog-boxes
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
Nice, but one can't possibly reproduce the contents of a whole form inside the $myDialog variable. Isn't there a way of pointing this dialog to a route or url instead?
Secondly, I am trying to open an off-canvas dialog and this doesn't work for that. Pls how do I do that? My requirements need me to open that off-canvas when a checkbox is enabled...