4

After upgrading from CF11 to CF2018, Update 3, none of my editable cfgrids are working. When I make an edit and then submit the form, the columns seem to get jumbled. I created the simplest cfgrid I could (below) but am still getting the same behavior.

<cfif isDefined("form.submitname")> 
  <cfdump var="#form#">
<cfelse>
  <cfform action="test.cfm" method="post" name="testform" id="testformId">
    <cfinput type="Submit" name="submitname" id="submitid">
    <cfgrid name="TestGrid" format="html" selectmode="edit">
      <cfgridcolumn name="A"> 
      <cfgridcolumn name="B">
      <cfgridrow data="john,doe">
      <cfgridrow data="steve,anon">
    </cfgrid>
  </cfform>
</cfif>

The grid displays correctly, but what I change 'john' to 'peter' and submit, I get the following dump: enter image description here

As you can see, it thinks 'peter' was entered as both the first and last name, and it also thinks that 'peter' was the original first name.

When I modify any of the fields in the second column, I get the following javascript error in the console:

TypeError: _dd.values[_de] is undefined.

The error is thrown by cfgrid.js

If I submit only a change in the second column, the dump is completely empty.

It seems like the cfgrid is mixing up columns or something.

Your thoughts?

1 Answers1

2

Ultimately the solution here is to move away from ColdFusion's implementation of <cfgrid> and roll your own grid-UI or.... wait for a patch from Adobe.

This is definitely a bug in ColdFusion, the error you are seeing is specifically a bug in the function ColdFusion.Grid.Actions.afterEdit()

I spent a little bit of time fiddling around with the JS generated with <cfgrid> and found that they index into the columns incorrectly

You can override ColdFusion's implementation of ColdFusion.Grid.Actions.afterEdit() with your own to create a possible workaround ( I ran on Solaris 11.4 - Apache - ColdFusion 2018 : Update 3 )

<Body>

<cfif isDefined("form.submitname")> 
  <cfdump var="#form#">
<cfelse>
  <cfform action="test.cfm" method="post" name="testform" id="testformId">
    <cfinput type="Submit" name="submitname" id="submitid">
    <cfgrid name="TestGrid" format="html" selectmode="edit">
      <cfgridcolumn name="A"> 
      <cfgridcolumn name="B">
      <cfgridrow data="john,doe">
      <cfgridrow data="steve,anon">
    </cfgrid>
  </cfform>
</cfif>

<script>

    ColdFusion.Grid.Actions.afterEdit = function(_d8, _d9, _da) {
        var _db = _d9.value;
        if (_db == this.editOldValue) {
            return;
        }
        if (this.insertInProgress == false && this.onChangeFunction) {
            this.onChangeHandler("U", this.selectedRow, _d9);
        } else {
            if (!this.dynamic) {
                rowidx = _d9.rowIdx;
                if (!rowidx && rowidx != 0) {
                    rowidx = _d9.row;
                }
                var _dc = ColdFusion.Grid.computeActualRow_editField(this.editFieldState, _d9.record.data.CFGRIDROWINDEX);
                var _dd = this.editFieldState[_dc - 1];
                var _de = _d9.colIdx;
                if (!_de && _de != 0) {
                    _de = _d9.column;
                }
                _de = _de + 1;
                if (_dd) {
                    if (this.multiRowSelection === true && this.insertInProgress == true) {
                        _de = _de - 1;
                    }
  //-------------------------------------------------------------------
  //Subtracted 1 from column index to correctly index array 
  //-------------------------------------------------------------------

                    _dd.values[_de -1][1] = _db;
                } else {
                    var _df = this.grid.getStore().getById(_d9.record.data.CFGRIDROWINDEX);
                    _dd = ColdFusion.Grid.Actions.initEditState(this, "U", _df, _dc);
                    var _e0 = this.editOldValue + "";
                    if (_d9.column.type == "date") {
                        if (_e0 && typeof _e0 == "string") {
                            _e0 = new Date(_e0);
                        }
                        var _e1 = "F, j Y H:i:s";
                        if (_d9.column && _d9.column.format) {
                            _e1 = _d9.column.format;
                        }
                        _dd.values[_de][1] = Ext.Date.format(_db, _e1);
                        _dd.values[_de][0] = _e0 ? Ext.Date.format(_e0, _e1) : _e0;
                    } else {
   //-------------------------------------------------------------------
  //Subtracted 1 from column index to correctly index array 
  //-------------------------------------------------------------------
                        _dd.values[_de -1][0] = _e0;
                        _dd.values[_de -1][1] = _db;
                    }
                }
                ColdFusion.Grid.Actions.computeEditField(this);
            }
        }
        this.editOldValue = null;
        this.fireSelectionChangeEvent();
    }
    ;
</script>

</BODY>

There are definitely a ton of other bugs plaguing this tag ... and its definitely worth noting that Lucee ( opensource ColdFusion engine) DOES NOT support this tag

Hedge7707
  • 557
  • 1
  • 5
  • 17
  • 1
    Agreed. Since they also deprecated/removed some of the UI stuff in 2018, it is likely this won't be the only upgrade issue you'll run into. Though it's probably not what you want to hear, switching to another (working) library now will ultimately save a lot of wasted time spent on chasing down these bugs. – SOS Mar 29 '19 at 19:13
  • 1
    Thanks! This is really helpful. And thanks for the workaround. I think we will start exploring our options. Any suggestions for a different grid-ui? I submitted a bug report to Adobe, by the way: https://tracker.adobe.com/#/view/CF-4204128 – whywontitwork Mar 29 '19 at 20:28
  • Might be worthwhile taking a look as mentioned in the comments at Ext.js grid , or possibly taking this approach ( although at preliminary glance I don't see them implementing edit functionality) https://github.com/cfjedimaster/ColdFusion-UI-the-Right-Way/blob/master/chapters/cfgrid/index.md – Hedge7707 Mar 29 '19 at 20:57