Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

handledEscapeKey and handleBackDropClick are no longer exist #1452

Closed
lucassus opened this issue Dec 23, 2013 · 2 comments
Closed

handledEscapeKey and handleBackDropClick are no longer exist #1452

lucassus opened this issue Dec 23, 2013 · 2 comments

Comments

@lucassus
Copy link

In 0.7.0 we don't have these methods on the modal instance.

Having these methods overridden could be pretty handy when we want to prevent incidental modal dialog close (on backdrop click or ESC key) when the form inside the dialog is dirty.
Like in this example: yakworks/angle-grinder@be49f6c#diff-9c41e572fbab986a5b3e613b482cd4e9L422

Is it currently possible to override this behavior?

@lucassus
Copy link
Author

We could extend backdrop and keyboard options to accept functions, so we should be able to do something like:

// modalBackdrop directive

        scope.close = function (evt) {
          var modal = $modalStack.getTop();
          if (modal && modal.value.backdrop) {
            var backdrop = modal.value.backdrop;
            if (backdrop === 'static') { return; }

            evt.preventDefault();
            evt.stopPropagation();

            if (typeof backdrop === 'function') {
              if (backdrop(modal.value.modalScope)) {
                $modalStack.dismiss(modal.key, 'backdrop click');
              }
            } else {
              $modalStack.dismiss(modal.key, 'backdrop click');
            }
          }
        };
$modal.open({
  // ... other options
  backdrop: function(scope) {
    return scope.myForm.$pristine;
  }
});

@pkozlowski-opensource
Copy link
Member

This is the same as #967, need to fine good API for this use-case...

Closing as duplicate, feel free to comment more with suggestions on #967

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants