I'm trying to build an AJAX responder that may or may not require a modal dialog. Under certain circumstance I return commands that just update the page. Under other circumstance I need it to show a modal dialog form.

When the link has the 'use-ajax' class, all of the commands, including the 'modal_display', are fired. Of course, since I didn't use the 'ctools-use-modal' class on the link, the appropriate click event does't fire which actually creates the modal dialog. The resulting 'modal_display' falls on deaf ears. If I just use the 'ctools-use-modal' class on the link, then I always get a modal loading even if i don't need it.

Is there a convenient way to lazy load the modal dialog in this use case, or do I have to write a new ajax command prototype to accomplish this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Probably the modal_display command should be updated to open the modal if it's not already open. That seems like a 1 or 2 line patch.

rwohleb’s picture

Status: Active » Needs review
FileSize
521 bytes

I'm not sure if I'm using using the best way to check if the modal is already created or not, but here's a patch. It's based off of alpha4 since that's what I'm dealing with at the moment. It's a 3-line change, but if it's a pain that it's not based off dev just give me the word and I'll find the time to recreate it.

merlinofchaos’s picture

Does that work if the modal is opened, then closed, then opened again? Closing the modal doesn't actually close it, I think, it just hides it. I could be wrong, though.

rwohleb’s picture

I had originally tried testing the existence of Drupal.CTools.Modal.modal but that sticks around after being first created. Of course, opening, closing, and opening again didn't fly so well with this setup.

I chose testing for the existence of $('#modalContent') just because it's actually removed from the DOM on dismiss. Opening and closing multiple times worked fine for me when using either 'use-ajax' or 'ctools-use-modal'.

rwohleb’s picture

Category: support » feature

Setting this to feature request since it seems more appropriate.

merlinofchaos’s picture

Status: Needs review » Fixed

Sorry, this got totally missed inthe last run of reviews, but it's committed now! Thank you!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.