Is there a way to add a button (e.g. Cancel) which closes the modal window the same as clicking the X button?

Comments

markus_petrux’s picture

Status: Active » Fixed

Nope. This feature is not included in the API, you have to code.

You can include a button in the child form that reads "Close", and your submit handler can tell the modal frame to close, or you can add this button using javascript, with an onclick event handler that closes the modal frame.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Version: 6.x-1.6 » 6.x-1.7
Status: Closed (fixed) » Active

You can include a button in the child form that reads "Close", and your submit handler can tell the modal frame to close, or you can add this button using javascript, with an onclick event handler that closes the modal frame.

Can you please give a code example of how to do this? I've been trying with no success...
Thanks!

markus_petrux’s picture

Status: Active » Closed (fixed)

Please note this is mostly Forms API. You should know how to create a form, how to render more than one submit button in it, and how to attach your submit callback and proceed depending on the button than has been pressed. That's Forms API, out of the scope here. Then, once you're in your submit callback, just execute modalframe_close_dialog() when you want the modal frame to close. This project comes with one example module, you can also check for the Modal Frame Contribs Package, the Node Relationships module that I also coded using Modal Frame, and I think there are a few more contrib modules using this API. I'm really sorry, but I'm too busy, and I cannot do more. I share code, I try to help, but I cannot reach every single need. Maybe you can try in the development forumsm which is where I think users can help users best than the issues queue, which is one that I try to keep as clean of bugs as possible.

Anonymous’s picture

Status: Closed (fixed) » Active

Sorry to keep re-opening this, but I'm not looking to use a form, simply an HTML a tag that closes the modalframe popup.

I tried using the same/similar code that the default close button in the frame's title bar uses, but to no avail. Calling modalframe_close_dialog() in the click function for my link didn't seem to work either. I noticed mention of a close() function in the documentation that I thought might be what I need, but I couldn't then find it in your code to see how it worked...

Again, I'm happy to get support elsewhere, just want to make sure I'll get the right answers since my query seems modalframe-specific.
I do love this module, thanks for all the hard work markus!

tomotomo’s picture

You can use this call as an onclick: Drupal.modalFrameChild.triggerParentEvent('childClose', false); return false;

markus_petrux’s picture

tomotomo is right (thanks!), but that's when you want to close the modal frame from the child document itself, that stuff is defined in child.js. If you want to close from the parent document, then try with Drupal.modalFrame.close(false), defined in parent.js (see how it is used there searching for self.close).

Anonymous’s picture

Status: Active » Closed (fixed)

Thanks guys! I actually was trying to close the modalframe from the child page.

I still couldn't get it working at first, but then realised that the child frame didn't have my .js file loaded (only the parent). Starting to wonder if this isn't what I was forgetting all along...
Oh well, all working now. Thanks for the assistance!

bittindm’s picture

Using the suggestion from #6, this seems to work well. It turns all cancel buttons appearing in modal frames in to close buttons. Drop it in a .js file and make sure it's being included in the modal.

  $('.modalframe-page-wrapper #edit-cancel').click(function() { 
    Drupal.modalFrameChild.triggerParentEvent('childClose', false); return false;
  });