Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
wrong options are used in editGridRow in case of default recreateForm:false
29/11/2013
23:23
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hi Tony,

I found some bugs in form editing and analased the problem exactly. The problem is common and there are many ways to fix it. I'm not sure which way you prefer so I desided first to write the bug report before posting one of the fix.

At the beginning I found that onclickSubmit will be called sometimes with wrong value of frmoper parameter. Then I found that the problem that place if the default recreateForm:false are used, the user first opens Add dialog and then opens Edit dialog. In the case frmoper parameter will be always "add". If the user first opens Edit dialog then onclickSubmit will have frmoper parameter always as "edit". Later analyse shows that beforeCheckValues, beforeSubmit and many other callbacks will be allways called with all options of the first opened dialog (either Add or Edit).

Now I found the reason of the problem very quickly. editGridRow method create the form only once. After that it uses bind("click") and keydown (see the linethe linethe line, the linethe line and so on) to register event handlers. At the moment the new execution context with the corresponding outer variables will be created. So everytime when click-event handler will be executed it sees the options (one from outer variables) of the first opened dialog (Add or Edit).

The click event handles calls postIt, checkUpdates, fillData, getFormData. postIt function for example uses $t, IDs, frmgr, frmoper, frmtb, gID, p, postdata outer variables. LSLint displays the list of all outer varaibles used in all functions (all outer variables of all closures). It can be used to find all references to outer variables. So the values of the variables could be wrong.

One can demonstares the problem on the following simple code

function outerFunction0 (someText) {
    var outerVar = { option: someText };

    if ($("#testId").length <= 0) {
        // we bind only at the first call of outerFunction0
        $("<span id='testId'></span>").bind("someEvent", function () {
            alert(outerVar.option);
        }).appendTo("body");
    }
    $("#testId").text(someText);
}
outerFunction0("add");
$("#testId").trigger("someEvent"); // displays alert("add")
outerFunction0("edit");
$("#testId").trigger("someEvent"); // displays alert("add") too !!! 

There are many ways to fix the problem:

  • uses allways only recreateForm:true. In other words remove some part of editGridRow code and remove previous form directly on the start of editGridRow or just destroy the form instead of making it hidden. Some advantage of the approach – one solve the problem with multiple grids on the same page which have the same names of columns.
  • unbind and rebind all event handler always. the form can still stay hidden on close.
  • save all options with respect of jQuery.data in DOM element of the form. The event handlers should don't use any outer variables dierctly. Instead of that one should use jQuery.data to get the options and then do the rest.

The first code demonstrates the solution with unbinding/rebinding:

function outerFunction1 (someText) {
    var outerVar = { option: someText };

    if ($("#testId1").length > 0) {
        $("#testId1").unbind("someEvent1");
    } else {
        $("<span id='testId1'></span>").appendTo("body");
    }
    $("#testId1").text(someText);
    // bind every time. So the new execution context will be set
    $("#testId1").bind("someEvent1", function () {
        alert(outerVar.option);
    });
}
outerFunction1("add");
$("#testId1").trigger("someEvent1"); // displays alert("add")
outerFunction1("edit");
$("#testId1").trigger("someEvent1"); // displays alert("edit") 

The next code fragment demonstrates the usage of jQuery.data:

function outerFunction2 (someText) {
    var outerVar = { option: someText };

    if ($("#testId2").length <= 0) {
        $("<span id='testId2'></span>").bind("someEvent2", function () {
            var myVar = $("#testId2").data("myoptions");
            alert(myVar.option); 

        }).appendTo("body");
    }
    $("#testId2").text(someText);
    // set the options as data of DOM element
    $("#testId2").data("myoptions", outerVar);

}
outerFunction2("add");
$("#testId2").trigger("someEvent2"); // displays alert("add")
outerFunction2("edit");
$("#testId2").trigger("someEvent2"); // displays alert("edit") 

The jsfidle demo demonstrates the both  code which I included.

You should decide Tony which way you choose and fix the code coresponds to the choice.

Best regards
Oleg

02/12/2013
14:51
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Oleg,

Many Thanks for this. This week I will work hard on jqGrid and will make a decision.

Thank's again for your work on jqGrid.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

04/12/2013
16:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Oleg,

See this commit

Thanks. I hope this is the better solution. Should make the same change in viewGridRow

Best Regards,

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
62 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information