0

When I click the cancel button in the add modal, I get the following error in the jquery.jqGrid.js file:

"0x800a138f - JavaScript runtime error: Unable to get property 'a' of undefined or null reference"

I only get this error in Internet Explorer, Chrome works fine.

The second issue I am having is that I'm calling the add modal from a button:

 <button name="addbutton" id="addbutton" class="add-new-row btn btn-success addbutton" style="float:right; margin-top:1%; margin-left:1%;">Add</button>

and then using the following code in the grid JS file:

 $(".addbutton").on("click", function () {
    $("#grid").editGridRow("new",
{
    // add options
    //2lines added by Ilango
    top: 50, left: 100, width: 500,
    addCaption: "Add record Dialog",
    addParams: { position: "afterSelected" },//, addRowParams: editOptions 
    zIndex: 100,
    url: "/Transactions/Create",
    closeOnEscape: true,
    closeAfterAdd: true,
    reloadAfterSubmit: true,

    afterComplete: function (response) {
        if (response.responseText) {
            $('#grid').trigger('reloadGrid')
            // alert(response.responseText);
            //window.location.reload();
            //reDefineColWidth();
            // $('#grid').trigger('reloadGrid')
            window.history.back();
        }

    },

    //submit on enter key
    onInitializeForm: function ($form) {
        $("td.DataTD>.FormElement", $form).keypress(function (e) {
            if (e.which === $.ui.keyCode.ENTER) {
                $("#sData", $form.next()).trigger("click");
                return false;
            }
        });
    },


    //adjust position of add form modal
    beforeShowForm: function (form) {
        //alert('adding' + "#editmod" + grdNames[0].id);
        //var dlgDiv = $("#editmod" + grdNames[0].id);
        var dlgDiv = $("#editmod" + $('#grid')[0].id);
        //var dlgDiv = jQuery("#editmodgrid");
        var parentDiv = dlgDiv.parent(); // div#gbox_list
        var dlgWidth = dlgDiv.width();
        var parentWidth = parentDiv.width();
        var dlgHeight = dlgDiv.height();
        var parentHeight = parentDiv.height();

        // Grabbed jQuery for grabbing offsets from here:
        //http://stackoverflow.com/questions/3170902/select-text-and-then-calculate-its-distance-from-top-with-javascript
        var parentTop = parentDiv.offset().top;
        var parentLeft = parentDiv.offset().left;


        // HINT: change parentWidth and parentHeight in case of the grid
        //       is larger as the browser window
        dlgDiv[0].style.top = Math.round(parentTop + (parentHeight - dlgHeight) / 2) + "px";
        //400 offset from left
        dlgDiv[0].style.left = Math.round(parentLeft + 500 + (parentWidth - dlgWidth) / 2) + "px";

    },

    afterShowForm: function (form) {
        //alert('adding' + "#editmod" + grdNames[0].id);
        //var dlgDiv = $("#editmod" + grdNames[0].id);
        var dlgDiv = $("#editmod" + $('#grid')[0].id);
        //var dlgDiv = jQuery("#editmodgrid");
        var parentDiv = dlgDiv.parent(); // div#gbox_list
        var dlgWidth = dlgDiv.width();
        var parentWidth = parentDiv.width();
        var dlgHeight = dlgDiv.height();
        var parentHeight = parentDiv.height();

        // Grabbed jQuery for grabbing offsets from here:
        //http://stackoverflow.com/questions/3170902/select-text-and-then-calculate-its-distance-from-top-with-javascript
        var parentTop = parentDiv.offset().top;
        var parentLeft = parentDiv.offset().left;


        // HINT: change parentWidth and parentHeight in case of the grid
        //       is larger as the browser window
        dlgDiv[0].style.top = Math.round(parentTop + (parentHeight - dlgHeight) / 2) + "px";
        //400 offset from left
        dlgDiv[0].style.left = Math.round(parentLeft + 500 + (parentWidth - dlgWidth) / 2) + "px";

    },
});
});

When I click the submit button, the record is submitted, but only with the default values I have setup for each column, not the values that I entered into the modal. I don't have this issue using the built in navigation add button.

Please help! I've spent many, many hours trying to figure this out.

EDIT:

Here is the block of code where the error occurs if(!h.a):

 close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
 }
reakt
  • 500
  • 8
  • 25
  • Which version of jqGrid you use and from which fork ([free jqGrid](https://github.com/free-jqgrid/jqGrid), commercial [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or an old jqGrid in version <=4.7)? Which version of Internet Explorer, you use? You should always try with *non-minimized* version of jqGrid (`jquery.jqgrid.src.js` instead of `jquery.jqgrid.min.js`) before posting the question. If you start Developer Tools (press F12) and then run debug then you will be see the exact line of the jqGrid code, call stack of functions and you will see all local variables. – Oleg May 20 '16 at 19:21
  • I'm on jqGrid 4.4.4. I'm nearly done with the project, and unfortunately I don't have time to upgrade. – reakt May 20 '16 at 19:29
  • It's very bad that you use retro version, but you still should reproduce the problem with non-minimized version of jqGrid and to post the line number of the error in `jquery.jqgrid.src.js`. Which version of Internet Explorer, you use? – Oleg May 20 '16 at 19:36
  • I noticed the error is only happening in IE. Let me reference the unminimized js file and debug to see which line of code is giving the error. – reakt May 23 '16 at 19:47
  • I've added the block of code where the error occurs in IE when clicking on the cancel button in the add modal. – reakt May 23 '16 at 19:55
  • It could be the bug in `jqmodal.js` module. I made some bug fixes. You can find the fixed version [here](https://github.com/free-jqgrid/jqGrid/blob/master/js/jqmodal.js) or [here](https://github.com/free-jqgrid/jqGrid/blob/master/js/min/jqmodal.js). You can include the new file **after** `jquery.jqgrid.min.js` or `jquery.jqgrid.src.js`. You can load it from CDN: `https://cdn.jsdelivr.net/free-jqgrid/4.13.3/js/min/jqmodal.js`. The code will *replace* the old code. I think it should work with jqGrid 4.4.4 too. – Oleg May 23 '16 at 20:03
  • It worked, but I have the same error in the jqmodal.js file. – reakt May 23 '16 at 20:10
  • It's good. Then you should use **non-minimized** version `https://cdn.jsdelivr.net/free-jqgrid/4.13.3/js/jqmodal.js` and see where exactly the error take place. I can suppose that jqGrid calles it with wrong parameters. You can download my code and replace `if (h.a) {` to `if (h != null && h.a) {`. It would be interesting if you would repeat the same test with full replaced version of jqGrid: to free jqGrid 4.13.3. If the same problem exist in free jqGrid then I should fix the code too. – Oleg May 23 '16 at 20:16
  • I tried free jqGrid 4.13.3 from the jsdelivr cdn and I couldn't reproduce the bug. However, now there are several other things that don't work correctly, so I'll have to switch back to jqGrid 4.4.4. – reakt May 23 '16 at 20:34
  • I understand that full migration to 4.13.3 can required some minor changes of your code. I just want to know, whether the same bug exist in free jqGrid too. Thanks for the test. Is the place with the error, which you have [here](https://github.com/free-jqgrid/jqGrid/blob/master/js/jqmodal.js#L181)? Do you tried the usage of `if (h.a) { to if (h != null && h.a) {` instead of ``if (h.a) {`? – Oleg May 23 '16 at 20:39
  • Thanks Oleg. I might make those changes at some point down the line when I'm more comfortable with JS. I made the change to if (h != null && h.a), but it caused the cancel and close buttons to become unresponsive. – reakt May 23 '16 at 20:45
  • You are welcome! I made some changes in `jqmodal.js` and in the code which calls it because of real problems like youth. I rewrote the code of `jqmodal.js` to make it more readable. You can try to make more changes of the code of `jqmodal.js` or to invest some time in migration to 4.13.3. You should choose the best way yourself. – Oleg May 23 '16 at 20:52

0 Answers0