Prevent backspace on select2-multi

Hi, as title mentioned, I would like to know whether possible to addeventlistener and prevent backspace when searchbar is empty and last selected option is disabled.

EDIT: I am using 3.4.5 and for compatibility reason I am not able to upgrade to latest version for my production environment.

Untitled

$(document).on('ready', function () {
    document.addEventListener('keydown', DisableBackspace, true);
});

function DisableBackspace(event) {
    let target = event.target;

    if (target.classList.contains('select2-input') && event.keyCode == 8) {
        let ctrl = target.closest('.select2-container');
        if (ctrl == null)
            return;
        else if (ctrl.classList.contains('select2-container-multi')) {
            //select2-sizer
            let searchTerm = $('.select2-sizer').text();
            if (searchTerm == '') {
                let arr = ctrl.querySelector('ul.select2-choices').getElementsByClassName('select2-search-choice');
                if (arr.length > 0) {
                    let close = arr[arr.length - 1].querySelector('a.select2-search-choice-close');
                    if (close !== null) {
                        console.log('not null');
                        event.preventDefault();
                        return false;
                    }
                }
            }
        }
    }
}

UPDATE: I managed to solve this issue, forgot to put stopPropagation and got one logic placed backward. Here is the updated code:

function DisableBackspace(event) {
    let target = event.target;

    if (target.classList.contains('select2-input') && event.keyCode == 8) {
        let ctrl = target.closest('.select2-container');
        if (ctrl == null)
            return;
        else if (ctrl.classList.contains('select2-container-multi')) {
            //select2-sizer
            let searchTerm = $('.select2-sizer').text();
            if (searchTerm == '') {
                let arr = ctrl.querySelector('ul.select2-choices').getElementsByClassName('select2-search-choice');
                if (arr.length > 0) {
                    let close = arr[arr.length - 1].querySelector('a.select2-search-choice-close');
                    if (close == null) {
                        event.stopPropagation();
                        event.preventDefault();
                        return false;
                    }
                }
            }
        }
    }
}