Search code examples
c#.netlightswitch-2013

Lightswitch submit a form on enter key


I am working on lightswitch application ,in this application normal form submit is happening on button click . I want to do the same on enter key press . I am using Htmlclient.here check screenshot


Solution

  • Along similar lines to my answer in the following post:

    Lightswitch HTML - disabling the CTRL + S functionallity

    You should be able to achieve this by adding the following code into your screen's created method:

    $(window).one("pagechange", function (e, data) {
        var $page = $("#" + screen.details._pageId);
        var $button = $page.find(".msls-save-button,.msls-ok-button");
        $page.keydown(function (e) {
            if (e.which === $.mobile.keyCode.ENTER) {
                $button.trigger("vclick");
                return false;
            }
        });
    });
    

    The jQuery mobile pagechange handler is needed to ensure that your screen is rendered (and _pageId is defined) before adding the keydown handler for the enter key.

    If the enter key is pressed, this handler executes the vclick against the commit button (identified by matching either the msls-save-button or msls-ok-button classes) and this instigates the commit on the screen.