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?
Comment | File | Size | Author |
---|---|---|---|
#2 | modal-display-with-use-ajax-1134378-2.patch | 521 bytes | rwohleb |
Comments
Comment #1
merlinofchaos CreditAttribution: merlinofchaos commentedProbably 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.
Comment #2
rwohlebI'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.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedDoes 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.
Comment #4
rwohlebI 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'.
Comment #5
rwohlebSetting this to feature request since it seems more appropriate.
Comment #6
merlinofchaos CreditAttribution: merlinofchaos commentedSorry, this got totally missed inthe last run of reviews, but it's committed now! Thank you!