Frequently I add a 'Cancel' link from inside $form['actions'] in forms that appear in the modal. I would really like when clicking those links to just close the modal, just like the top-right 'Close window'. I've tried giving them a .close class but this also gives the link a white color via CSS which for most admin themes make the link invisible.

Members fund testing for the Drupal project. Drupal Association Learn more


merlinofchaos’s picture

Hm. It looks like the click behavior is bound when the frame is rendered, not when the content is rendered. It looks like it would be easy enough to add a standard modal close class, though.

From javascript, I believe your code would look something like this in a behavior:

  .click(function() { 
    return false;

We could put that (or a working version in case I've typo'd something) in the modal's behavior and then in theory anyone could use it, but something like that could also go in any module's behavior to bind to a button specifically.

Dave Reid’s picture

Status: Active » Needs review
561 bytes
498 bytes

Cool. This works as expected. Here's a patch against 7.x-1.x and 6.x-1.x.

Dave Reid’s picture

Missed the context parameter in the D7 patch.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to both branches. Thanks for turning this into a patch!

Status: Fixed » Closed (fixed)

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