locked
Field Pre-set & Re-focus trigger enter key RRS feed

  • Question

  • User-893002196 posted

    Hi All,

    I have a code:

    $("#gs_jqgInventory_" + row_id + "_t_assignedUser").focus().val($("#gs_jqgInventory_" + row_id + "_t_assignedUser")); //Pre-set Value Re-Focus Field
    $("#gs_jqgInventory_" + row_id + "_t_assignedUser").keypress(); //Trigger enter key               --NOT WORK--    OR
    $("#gs_jqgInventory_" + row_id + "_t_assignedUser").trigger(jQuery.Event('keypress', { keycode: 13 })); //Trigger enter key     --NOT WORK--

    Unfortunately the keypress doesn't work. The focus is working fine, How can I trigger the enter key after field being focus as above my code?

    Please advise.

    Thanks.

    Regards,

    Micheale

    Friday, August 21, 2020 1:46 AM

All replies

  • User-893002196 posted

    Hi,

    I managed to solved it with this:

    $("#gs_jqgInventory_" + row_id + "_t_assignedUser").focus().val($("#gs_jqgInventory_" + row_id + "_t_assignedUser"));                            
                                $("#gs_jqgInventory_" + row_id + "_t_assignedUser").focus(function () {
                                    if (cntI == 1) {
                                        var e = jQuery.Event("keypress");
                                        e.which = 13
                                        $("#gs_jqgInventory_" + row_id + "_t_assignedUser").trigger(e);
                                        $("#" + subgrid_table_id)[0].triggerToolbar();
                                    }
                                });

    But this only work in IE NOT google chrome. How can make his work in Google Chrome?

    Please advise.

    Thanks

    Regards,

    Micheale

    Friday, August 21, 2020 7:03 AM
  • User1535942433 posted

    Hi micnie2020,

    Accroding to your description and codes,I couldn't reproduce your problems.

    I'm guessing that you have a jqgrid and you want  to focus on the jqgrid   and then  it could reset a value and  autosearch.

    I create a test like this:

     <link href="~/Content/jquery.jqGrid/ui.jqgrid.css" rel="stylesheet" />
        @*<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans" />
            <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />*@
        <link href="~/Content/ui.jqgrid-bootstrap-ui.css" rel="stylesheet" />
        <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/redmond/jquery-ui.css" />
        <script src="~/Scripts/jquery-3.0.0.min.js"></script>
        <script src="~/Scripts/jquery-ui-1.10.0.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/free-jqgrid/4.13.5/js/jquery.jqgrid.min.js"></script>
        <script>
                $(function() {
                    $("#jgrid").jqGrid({
                        url: "/Jqgridhyperlink/list",
                        datatype: 'json',
                        mtype: 'Get',
                        colNames: ['ID', 'Builder Name', 'Payments'],
                        colModel: [
                            {
                                key: true, name: 'ID', index: 'ID', editable: true, formatter: 'showlink', formatoptions:
                                {
                                    baseLinkUrl: 'Detail', idName: 'ID'
                                }
                            },
                            { key: false, name: 'Name', index: 'Name', editable: true },
                            { key: false, name: 'Payments', index: 'Payments', editable: true },
    
                        ],
                        pager: jQuery('#jgrid'),
                        rowNum: 5,
                        rowList: [10, 20, 30, 40],
                        height: '100%',
                        viewrecords: true,
                        loadonce: true,
                        caption: 'Payments',
                        emptyrecords: 'No Payments Records are Available to Display',
                        jsonReader: {
                            root: "rows",
                            page: "page",
                            total: "total",
                            records: "records",
                            repeatitems: false,
                            Id: "0"
                        },
                        autowidth: true,
                        multiselect: false,
                    });
                    $('#jgrid').jqGrid('filterToolbar', { autosearch: true });
                    $('#jgrid').setGridParam(
                        {
                            datatype: 'json',
                            url: '/Jqgridhyperlink/list',
                            postData: JSON.stringify($("gs_jgrid_Name").val())
                         }
                    );
                    //$("#jgrid").focus().val($("#jgrid"));
    
                    $("#jgrid").focus(function () {
                        $("#gs_jgrid_Name").val("a");
                        var e = jQuery.Event("keypress");
                        e.which = 13;
                        console.log("e.which");
                        console.log(e);
    
                        $("#jgrid").trigger(e);
                        console.log("trigger e");
                        $("#jgrid")[0].triggerToolbar();
                        console.log($("#jgrid")[0]);
                    });
                });
    
        </script>
       <div>
            <table id="jgrid"></table> 
        </div>

    Result:

    I suggest you could post your full codes about jqgrid and more details of your requirment to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    Monday, August 24, 2020 4:29 AM