admin管理员组

文章数量:1323529

I'm using Uikit with Angularjs and i need create possibly a directive that prevent the closing of the Modal when i press esc button. I tried with this way:

mainApp.directive('ngEsc', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress keyup", function (event) {
            if(event.which === 27) {
                event.preventDefault();
            }
        });
    };
});

And then put the directive on the modal

Test modal

But it still closes. Is there any other way?

I'm using Uikit with Angularjs and i need create possibly a directive that prevent the closing of the Modal when i press esc button. I tried with this way:

mainApp.directive('ngEsc', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress keyup", function (event) {
            if(event.which === 27) {
                event.preventDefault();
            }
        });
    };
});

And then put the directive on the modal

Test modal

But it still closes. Is there any other way?

Share Improve this question asked Mar 11, 2016 at 14:08 Atlas91Atlas91 5,90417 gold badges75 silver badges148 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

Below is how I fixed this issue in my angular 7 project;

uikit.modal("#modalR", { bgClose: false, escClose: false, modal: false, keyboard:false}).show(this.data)

for more information please visit link below https://github./uikit/uikit/blob/develop/src/js/core/modal.js#L15:L21

Have you tried to use the option keyboard:false?

UIkit.modal("#modal element", {bgclose: false, keyboard:false}).show();

It worked in my case.

You can see the core of modal uikit as well: modal.js

You can try use "return false" instead of preventDefault:

mainApp.directive('ngEsc', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress keyup", function (event) {
            if(event.which === 27) {
                return false;
            }
        });
    };
});

本文标签: javascriptUkit modal prevent close on escape buttonStack Overflow