Lightswitch HTML - disabling the CTRL + S function

2019-07-24 16:17发布

It turns out then when you have an Add/Edit screen open (dialog or full), that you can hit CTRL + S to save the screen. This avoids all validation I have coded, and also does not matter if I have disabled Lightswitch's own save button. How can I disable this?

on a browse or view screen, this does not occur and the user is only able to save there web page

1条回答
smile是对你的礼貌
2楼-- · 2019-07-24 16:57

One option to disable the Ctrl+S is to remove the msls-save-button css class from your screen's save button. This can be done in your screen's created method as follows:

myapp.AddEditScreen.created = function (screen) {
    $(window).one("pagechange", function (e, data) {
        var $page = $("#" + screen.details._pageId);
        var $button = $page.find(".msls-save-button");
        $button.removeClass("msls-save-button");
    });
};

The jQuery mobile pagechange handler is needed to ensure that your screen is rendered (and _pageId is defined) as covered in my answer to the following post:

LightSwitch Tabbed screen in Browse template

This approach does the trick because the LightSwitch msls library executes the vclick against the commit button by matching either the msls-save-button or msls-ok-button classes. Therefore, if the msls-save-button class is removed, the vclick cannot be triggered and in essence the Ctrl+S is ignored.

The following lists the msls library function which handles the short-cut keys (the msls-save-button vclick handling is covered at the end of the function):

function _handleScreenKeyboardShortCuts($page, navigationUnit) {
    var buttonsNeeded = navigationUnit._buttonsNeeded,
        showCancel;
    if (!buttonsNeeded) {
        return;
    }
    showCancel = buttonsNeeded.showSaveDiscard ||
        buttonsNeeded.showOkCancel;
    if (!(showCancel || buttonsNeeded.showOk)) {
        return;
    }
    $page.keydown(function (e) {
        if (msls_shell._currentNavigationOperation ||
            $.mobile.popup.active) {
            return;
        }
        if (showCancel && _isCancelShortCutKey(e)) {
            $(".msls-discard-button,.msls-cancel-button",
                $.mobile.activePage).trigger("vclick");
            return false;
        } else if (_isCommitShortCutKey(e)) {
            $(".msls-save-button,.msls-ok-button",
                $.mobile.activePage).trigger("vclick");
            return false;
        }
    });
}
查看更多
登录 后发表回答