Event handlers do not get attached to fields in grid control... - Forum - Rollbase - Progress Community

Event handlers do not get attached to fields in grid control...

 Forum

Event handlers do not get attached to fields in grid control...

  • I have a lookup field (Part) and numeric field (quantity) which both have onChange event handlers set up. I want to autofill the Unit Cost onChange for the lookup, and calculate the total cost onChange for the quantity. However, the handlers are not present if you Add a record in grid control. Thanks, Mike
  • The onUpdate grid control handler could be used in this situation...

    onUpdate:

    if (typeof jl_getPartPrice =='function') jl_getPartPrice(this);


    Javascript on a page:

    function jl_getPartPrice(rowField)
    {
    alert(rowField.name);
    }


    This works fine for Text fields, but not for Lookup fields. When a lookup field's onchange event handler is fired, "this" = a reference to [object window] and not a reference to the lookup field.

    Eventually, the desired outcome would be to:
    1) Add A Row to the Grid.
    2) On each row, there is a Lookup "Part", and text fields "Qty" and "Unit Price", etc.
    3) When the Part lookup has changed (a part has been selected), the Unit Price will get automatically populated using rbf_getFields(...).

    Thanks,
    Mike
  • You're right, HTML event handlers do not apply when field is used in a Grid, since strictly speaking there is no field in this case. You should use event handlers capabilities provided by grid.
  • How can I determine which row on the grid fired the onUpdate trigger?

    If I set the trigger to this: if (typeof jl_getPartPrice =='function') jl_getPartPrice(this);

    I can get the fieldName_rowIndex from "this.name", from which I can extract the rowIndex. However, I can not obtain the fieldName_rowIndex if the field that is firing the trigger is a Lookup field. "this" comes up as undefined in that case.

    Thanks,
    Mike
  • If you use a special symbol @@ in the body of your grid handler it will be replaced by current row. Please refer to Chapter 7 of documentation for more info.
  • Yea, that's exactly what I needed. Must have missed it.

    Thanks!
  • Pavel-

    There seems to be a bug with rbf_setGridValue(fieldName, rowIndex, value). The function only works if rowIndex = 0.

    onUpdate grid handler:

    if (typeof jl_getPartPrice =='function') jl_getPartPrice(@@);


    JavaScript on page w/ Grid:

    function jl_getPartPrice(jl_rowIndex)
    {
    alert("CHANGING ROW: jl_rowIndex= " + jl_rowIndex);

    //ONLY WORKS IF jl_rowIndex = 0:
    rbf_setGridValue('unit_cost', jl_rowIndex, "$9999");

    //WORKS:
    //rbf_setGridValue('unit_cost', 0, "$9999");

    //DOES NOT WORK:
    //rbf_setGridValue('unit_cost', 1, "$9999");
    }
  • This function is pretty simple and tends to work in my testing. However if you see an issue try to replace this function with actual code below and remove try / catch block:


    function rbf_setGridValue(fieldName, rowIndex, value) {
    try {
    var field = eval("document.theForm."+fieldName+'_'+rowIndex);
    if (field)
    field.value = value;
    }
    catch (e) {
    }
    }
  • I tried using your code above and got the same results. I removed the try/catch and inserted an alert.. Here's the whole code:


    function jl_getPartPrice(jl_rowIndex)
    {
    alert("CHANGING ROW#: jl_rowIndex= " + jl_rowIndex);
    rbf_setGridValue('unit_cost', jl_rowIndex, "$9999");
    }
    function rbf_setGridValue(fieldName, rowIndex, value)
    {
    var field = eval("document.theForm."+fieldName+'_'+rowIndex);
    if (field)
    {
    field.value = value;
    alert("WORKS!");
    }
    else
    alert("ERROR! fieldName= " + fieldName + "\n rowIndex= " + rowIndex + "\n value= " + value + "\n field= " + field);
    }


    Screenshots:

  • Well, this means that field in row 1 does not exist. If you want me to take a closer look please submit support request with the following info:
    - application
    - object
    - page to look for
    - any additional info
  • Pavel-

    I submitted a support request with all of that info yesterday.

    ID: 8790013
    TITLE: "Summary - Possible bug with rbf_setGridValue() demonstration"

    I re-tested the code and it appears to work fine in Internet Explorer 8, but does not work (ie. field = undefined) in both FireFox 3.5.8 and Google Chrome 4.0.249.89.

    Thanks,
    Mike