Skip to main content
7 votes
Accepted

Open ajax dialog with JavaScript

You can trigger Ajax in custom javascript. See How to Trigger Existing, Non-Form Ajax from JavaScript Event In your case an Ajax dialog: var ajaxSettings = { url: '/node/1', dialogType: 'modal', ...
4uk4's user avatar
  • 101k
5 votes
Accepted

Add event listener to modal close

In core dialog.js code I've found a following lines of code. $(window).trigger('dialog:afterclose', [dialog, $element]); and $(window).trigger('dialog:beforeclose', [dialog, $element]); Means that ...
Lianik's user avatar
  • 66
4 votes

How do you create a link to a modal dialog?

This html looks ok, but did you include the core/drupal.dialog.ajax js library that attach event to your link ? In twig : {{ attach_library('core/drupal.dialog.ajax') }} In PHP, it looks like this :...
Oulalahakabu's user avatar
  • 1,323
3 votes
Accepted

Why is ScrollTopCommand not working?

You need to include the views/views.ajax lib: $form['#attached']['library'][] = 'views/views.ajax';
David DIVERRES's user avatar
3 votes
Accepted

How do I trigger a modal from a template that points to a controller returning an AJAX response

You're trying to trigger your modal in multiple ways. Right now your twig is saying to open the href in a modal, but your controller is not return html, it's returning a json/ajax response to open its ...
sonfd's user avatar
  • 8,077
3 votes
Accepted

How to populate an Entity Reference field from a modal AjaxResponse?

Figured out it was the InvokeCommand i needed and to set "val" to the referenced entity title with id in (). $nid = $form_state->getValue('nid'); $node = Node::load($nid); $value = $node->...
liquidcms's user avatar
  • 1,318
3 votes

How do I theme the core modal with twig?

Modals in Drupal are built with jQuery UI. If you want to add just some class to the modal window, you can make use of the dialogClass option. <a href="/node/11" class="use-ajax" data-dialog-...
leymannx's user avatar
  • 18.6k
3 votes
Accepted

How to get my button in a dialog click?

for me that submits the node: (function (window, Drupal, $) { Drupal.behaviors.drafter = { attach: function attach(context) { var button = $('#edit-submit'); var newbutton = button....
drugan's user avatar
  • 466
2 votes
Accepted

How do I use Bootstrap theme's modal.jquery.ui.bridge's mapped events?

The technical reason it's not doing anything is that the value is retrieved as a string and not as a Function object. You shouldn't pass anonymous functions in data attributes. This would require ...
Mark Carver's user avatar
2 votes
Accepted

How can I open a node edit form in an overlay (modal window)?

You can just add css class use-ajax and data-dialog-type="modal" to the link. For example: <a href="/node/add/task" class="use-ajax" data-dialog-type="modal"&...
Elin Y.'s user avatar
  • 7,402
2 votes
Accepted

How to get node title using this query on template?

You shouldn't do queries like like that. You should use EntityQuery. See https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21Query%21QueryInterface.php/function/QueryInterface%3A%...
beltouche's user avatar
  • 729
2 votes

Form in modal dialog: Template suggestions have weird random suffix

Create a .module in your module folder ex : library_assets/library_assets.module in the .module file use this HOOK to create a new form suggestion that will be dynamically equal to form--{form-id}....
Marwen Amri's user avatar
2 votes

How do form #states interact with dialog action buttons, if at all?

This doesn't answer the question itself, but since I struggled for a while to get this all syncd up I figured I should drop the work into something that people might hit from google. To get the ...
Mrweiner's user avatar
  • 1,931
2 votes
Accepted

Show node links in modal buttonpane

Ah, I just figured out from core/misc/dialog/dialog.ajax.js that I need wrapper with class form-actions. <div class="form-actions"> <a href="mailto:[email protected]" ...
mixerowsky's user avatar
  • 1,581
2 votes

Add event listener to modal close

The clue was seeing the Drupal's modal just uses jquery widgets. So a simple Google for "jquery widget close event" lead me to this SO answer. So the solution is: $('#drupal-modal').on('...
Felix Eve's user avatar
  • 6,283
2 votes

How do I display a modal dialog on page load, with working title and dialog options, using OpenModalDialogCommand?

It turns out the code above was working fine -- the problem was that the site was using a Bootstrap subtheme, and Bootstrap was configured to override the standard dialog behavior. Turning off ...
WRD's user avatar
  • 319
2 votes
Accepted

Modal form opened from modal form doesn't submit

This is a gotcha of AJAX forms. When you load an AJAX form via AJAX it loses its AJAX functionality. In order to keep it working, for the form that is getting loaded via ajax, you need to add a url ...
No Sssweat's user avatar
  • 31.5k
1 vote

Can't access data posted from Dialog.ajax to dialog box

You have to replace the data key with submit. Drupal.ajax() transfers the submit key to the data key of $.ajax() but ignores a data key already set: var exportActionDialog = Drupal.ajax({ dialog: ...
4uk4's user avatar
  • 101k
1 vote
Accepted

Custom form calls different form in modal, submit/ajax callback of second form not called

Since you're programmatically setting a modal with $response->addCommand(new OpenModalDialogCommand($this->t('Test'), $modal_form, $dialog_options)); For the form that is in the modal, Drupal ...
No Sssweat's user avatar
  • 31.5k
1 vote
Accepted

What is the correct way to set language used by a modal form?

If language is by URL or path prefix, you'll need to make sure the AJAX call is to the correct URL or path prefix, to load the correct language.
Jaypan's user avatar
  • 17.8k
1 vote
Accepted

Entity Browser Modal closes on Exposed Filter Submit Button

It was my fault all along, since I have overwritten views-view.html.twig in my custom theme and removed the div where the "js-view-dom-id-xxx" is set. This one is obviously needed when the ...
Berry Dingle's user avatar
1 vote

Display status message after submitting modal popup form

After redirection the \Drupal::messenger() may not work. So try with the Drupal OpenModalDialogCommand use Drupal\Core\Ajax\OpenModalDialogCommand; /** * {@inheritdoc} */ public function submitForm(...
Rahulmon Johnson's user avatar
1 vote
Accepted

Using attach_library in a modal

render() only works because of EarlyRenderingControllerWrapperSubscriber, which should have been removed by now: * In other words: this just exists to ease the transition to Drupal 8: it * allows ...
4uk4's user avatar
  • 101k
1 vote
Accepted

How to have a dialog box displayed automatically when a page is reached without having to click the link?

Your JS needs to be formatted like this: (function ($, Drupal) { Drupal.behaviors.myThemeBehavior = { attach: function (context, settings) { $('.use-ajax', context).once('auto-open').each(...
No Sssweat's user avatar
  • 31.5k
1 vote

Creating ajax modal from event

How can I create a modal popup from a CartEvents::CART_ENTITY_ADD event subscriber? Am I missing something to do with the libraries or something wrong with my php? You can't return a response from ...
4uk4's user avatar
  • 101k
1 vote

on click popup load another popup and close other popup

As per my understanding you want to open a new modal from an existing open modal. I have checked the same case in latest drupal 8.7.5 and it works without a problem. You don't have to add any ...
Manish Jain's user avatar
1 vote
Accepted

Show rendered node in jQuery modal through JSON

I can suggest you to check with AjaxResponse, it will return the json response object. $response = new AjaxResponse(); And use below to open content in modal or as dialog. $response->addCommand(...
Manish Jain's user avatar
1 vote

Create a modal popup

You should use the ctools_modal_text_button function to render your "popup-opener" links. ctools_include('ajax'); ctools_include('modal'); ctools_modal_add_js(); $link = ctools_modal_text_button('...
milkovsky's user avatar
  • 5,364
1 vote
Accepted

How to display a form in modal dialog on page load?

What I did, hide the link in the body and from javascript trigger the click event of the link, will show the dialog.
Md. Shafiq Hossain's user avatar
1 vote
Accepted

Modal Form Submission

Populating a form field should be done via '#default_value' => ... instead of '#value' => ...
theuni's user avatar
  • 865

Only top scored, non community-wiki answers of a minimum length are eligible