0

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
        };
    }
);
0

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

  • 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 – bhavesh kesharani Oct 24 '18 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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