1

When I tried to click outside of the modal area modal getting closed how to prevent that and modal should not be closed when the user clicks outside of modal.

define([
        "jquery",
        "Magento_Ui/js/modal/modal"
    ], function($, modal){
        var modalls = [];
        var AlertModal = {

            initModal: function(config, element) {
                modalls.push($(config.target));
                $target = $(config.target);
                $target.modal();
                $element = $(element);
                $("#cancelConfirmationMessageBtn").unbind('click').click(function() {
                // jQuery("#cancelConfirmationMessageBtn").click(function(){
                    var url = window.location.href,
                    parts = url.split("/"),
                    lastPartOfUrl = parts[parts.length-2];
                    if(lastPartOfUrl == 'checkout') {
                        var options = {
                            type: 'popup',
                            responsive: true,
                            innerScroll: false,
                            clickableOverlay: true,
                            title: "",
                            buttons: [{
                                text: $.mage.__('OK'),
                                class: 'button',
                                click: function () {
                                    popupdata.modal('closeModal');
                                    var tt = modalls.pop();
                                    modalls.push(tt);
                                    tt.modal('openModal');
                                }
                            }]
                        };
                        var popupdata = $('<div />').append($('#warning-message'));
                        modal(options, popupdata);
                        popupdata.modal('openModal');
                        $('.warning-message').css('display','block');
                        //$(".modal-header").hide();
                       // $(".modal-content").css({"padding":"20px","margin-top": "20px"});
                       // $(".modal-footer").css("border-top", "none");
                        $(".modal-inner-wrap").css("width", "60%");
                    }
                    var tt = modalls.pop();
                    modalls.push(tt);
                    tt.modal('closeModal');
                });
                jQuery("#okOtherMessageBtn").click(function(){
                    var tt = modalls.pop();
                    tt.modal('closeModal');
                });
                $element.ready(function() {
                    $target.modal('openModal');
                    $(".modal-header").hide();
                    $(".modal-footer").hide();
                    $(".modal-inner-wrap").css("width", "60%");
                });
            }
        };

        return {
            'alert': AlertModal.initModal
        };
    }
);

2 Answers 2

4

Your options is set to close the modal if user clicks outside. Just change this line

clickableOverlay: true

into

clickableOverlay: false

For more information here

3
  • 1
    I tried but it is not working in magento 2.2.6 version. the thing is its working properly in magento 2.2.5. I got issue after updating from 2.2.5 to 2.2.6 Oct 24, 2018 at 7:51
  • @bhaveshkesharani have you found any solution for this?
    – Knight017
    Dec 13, 2019 at 6:23
  • @Knight017 yes i found the solution for same Jan 10, 2020 at 9:27
0

It's a known bug. Please check out the below link. https://github.com/magento/magento2/issues/7399

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.