Search code examples
javascriptjqueryhtmlfroalasweetalert2

Sweet alert 2 closing when pressing space bar with Froala editor


Currently I am creating a SweetAlert2 that displays a Froala HTML editor, This is done in a function called CreatePolicyPopUp (which is triggered on a button click). However, when I press the space bar inside the editor it closes the sweet alert. Previously I was using CKEditor for the html editor but this problem did not happen.

This is a stripped down version of the code that creates the sweet alert and initializes the editor.

CreatePolicyPopUp: function (fromTemplate, duplicatePolicyID, allVals) {
        $.get("CreatePolicy.html", function (data) {
            swal({
                html: data,
                showCloseButton: false,
                showCancelButton: false,
                width: 800,
                showConfirmButton: false
            }).then(function () {

            });

            /*initialize editor*/
            $('#froalatextarea').froalaEditor();

        });
    },

Could there be anything conflicting between froala and sweetalert2? Or is there a way to disable close on pressing the space bar?

If needed here is the html for my CreatePolicy.html file and also the whole CreatePolicyPopUp function is included.


Solution

  • Thanks to this post I found with a similar problem on an old version of sweetalert. I found out that the sweet alert 2 plugin is listening out for a space key pressed using charactercodes (the space charcode is 32) so to fix it I removed the space bar character from the close sweet alert event.

    The easiest way to remove this in the sweetalert2.min.js file was to find "||32===r" and delete it.