6 Replies Latest reply: Nov 15, 2012 11:31 AM by AlHolden RSS

    cfgrid (type=flash) - how to capture in-cell keystroke event?

    AlHolden Community Member

      Yep, I'm maintaining a Flash type cfform that was authored a few years ago. The application is on CF9 now.

       

      How can my application sense when a user has keypressed within a CFGRID cell?

       

      I've introduced a change event listener to the cfgrid via the onchange tag attribute. The event fires when the mouse clicks within any cell.

       

      But keyboard navigation or individual cell keystrokes to not trigger a change, even when traversing to another cell via Tab or Enter.

       

      I've also tried using the keyDown event, but that is only triggered when navigating the overall grid. It does not fire when a cell has focus - the user is typing within it.

       

      keyUp doesn't work either, nor does keypress, keydown, keyup or any of my other exhaustive deriviation attempts. I've tried to locate a complete list of AS 2.0 event names, but have had no luck, even within Adobe's own pdf docs. If anyone has an example from their own personal museam, I'd love to see it.

       

      Did I mention that this is a Flash cfform? Thought so...

        • 1. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
          BKBK Community Member

          <cfset cities = "Rome,Athens,Canberra,Brasilia,Paris">

          <cfset countries = "Italy,Greece,Australia,Brazil,France">

          <cfset dateObj = arrayNew(1)>

          <cfset dateObj[1] = createdate(2009,11,21)>

          <cfset dateObj[2] = createdate(2010,2,3)>

          <cfset dateObj[3] = createdate(2009,4,14)>

          <cfset dateObj[4] = createdate(2010,5,23)>

          <cfset dateObj[5] = createdate(2011,11,11)>

           

          <cfform name="cities" format="flash">

             

          <cfformitem type="script">

          function showItinerary(){

              alert('City:' + geoGrid.selectedItem.city + ', Travel date:' + geoGrid.selectedItem.travelDate);

          }

          </cfformitem>

           

          <cfgrid name="geoGrid" onChange="showItinerary();">

          <cfgridcolumn name="city" header="City">

          <cfgridcolumn name="country" header="Country">

          <cfgridcolumn name="travelDate" header="Travel Date">

           

          <cfloop index="i" from="1" to="#ListLen(cities)#">

          <cfgridrow data ="#ListGetAt(cities, i)#, #ListGetAt(countries, i)#, #dateFormat(dateObj[i],'dd mmm yyyy')#">

          </cfloop>

          </cfgrid>

           

          </cfform>

          • 2. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
            AlHolden Community Member

            Thanks for the response, BKBK!

             

            However, your example will fire an event when one clicks on a cell - but does not provide insight into the event of typing inside a cell. This grid is not even editable.

             

            I've extended your example below to demonstrate the issue. The desire is for the text input below the grid to update with a new "last pressed" key code with every stroke made inside a grid cell. But when executed, it only fires when one clicks between cells using the mouse.

             

            Thanks again.

             

            <cfset cities = "Rome,Athens,Canberra,Brasilia,Paris">

            <cfset countries = "Italy,Greece,Australia,Brazil,France">

            <cfset dateObj = arrayNew(1)>

            <cfset dateObj[1] = createdate(2009,11,21)>

            <cfset dateObj[2] = createdate(2010,2,3)>

            <cfset dateObj[3] = createdate(2009,4,14)>

            <cfset dateObj[4] = createdate(2010,5,23)>

            <cfset dateObj[5] = createdate(2011,11,11)>

             

            <cfform name="cities" format="flash">

               

                <cfformitem type="script">

                function showItinerary(){

                    changeResult.text = 'last key code is:' + Key.getCode();

                }

                </cfformitem>

               

                <cfgrid name="geoGrid" onChange="showItinerary();" selectmode="edit">

                    <cfgridcolumn name="city" header="City">

                    <cfgridcolumn name="country" header="Country">

                    <cfgridcolumn name="travelDate" header="Travel Date">

                    <cfloop index="i" from="1" to="#ListLen(cities)#">

                        <cfgridrow data ="#ListGetAt(cities, i)#, #ListGetAt(countries, i)#, #dateFormat(dateObj[i],'dd mmm yyyy')#">

                    </cfloop>

                </cfgrid>

               

                <cfinput name="changeResult" type="text" size="60" />

            </cfform>

            • 3. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
              BKBK Community Member

              I now understand what you're looking for. I'll have another go.

              • 4. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
                BKBK Community Member

                Here is a start. I have stayed with the form simply because it is now familiar.

                 

                In this example, the value of the edited city field is copied into the changeResult input field.

                 

                <cfset cities = "Rome,Athens,Canberra,Brasilia,Paris">

                <cfset countries = "Italy,Greece,Australia,Brazil,France">

                <cfset dateObj = arrayNew(1)>

                <cfset dateObj[1] = createdate(2009,11,21)>

                <cfset dateObj[2] = createdate(2010,2,3)>

                <cfset dateObj[3] = createdate(2009,4,14)>

                <cfset dateObj[4] = createdate(2010,5,23)>

                <cfset dateObj[5] = createdate(2011,11,11)>

                 

                <cfform name="cities" format="flash">

                 

                <cfformitem type="script">

                function registerKeyStrokes(){

                    var listener:Object = {};

                    var changeField=changeResult;   

                    listener.cellEdit = function(evt:Object):Void {

                        changeField.text = evt.target.selectedItem.city;

                    }

                    geoGrid.addEventListener('cellEdit',listener);

                }

                </cfformitem>

                 

                <cfgrid name="geoGrid" selectmode="edit" format="flash" onchange="registerKeyStrokes()">

                <cfgridcolumn name="city" header="City" >

                <cfgridcolumn name="country" header="Country">

                <cfgridcolumn name="travelDate" header="Travel Date">

                <cfloop index="i" from="1" to="#ListLen(cities)#">

                    <cfgridrow data ="#ListGetAt(cities, i)#, #ListGetAt(countries, i)#, #dateFormat(dateObj[i],'dd mmm yyyy')#">

                </cfloop>

                </cfgrid>

                <cfinput name="changeResult" type="text" size="60">

                 

                </cfform>

                • 5. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
                  BKBK Community Member

                  Does the silence mean you finally finished it off? If not, here then is one solution.

                   

                  You already have the string typed in by the user. All you have to do to get the last keystoke is pick out the last character of the string! Something like this

                   

                  function registerKeyStrokes(){

                          var listener:Object = {};

                          var changeField=changeResult;   

                          listener.cellEdit = function(evt:Object):Void {

                              var str:String = evt.target.selectedItem.city;

                              changeField.text = 'Last keystroke is: ' + str.substr(str.length-1,1);

                          }

                          geoGrid.addEventListener('cellEdit',listener);

                      }

                  • 6. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
                    AlHolden Community Member

                    The silence means that I'm just a busy guy ;-]

                     

                    Thanks for all your efforts, but I've come to the conclusion that the individual cells within a cfgrid like this simply do not expose an event we can use to sense keystrokes. All of these attempts only "see any action" when one navigates beyond the individual cell's control. I wanted to know when a user tapped a key WITHIN a cell.

                     

                    I'll bet the original thinking - when this component was created - was to provide all those nifty array elements in the submitted form scope - which tell us which rows and cells were changed and why ("RowStatus.Action" et.al.). They assumed that negated the need for complex scripted grid event management & bubbling in their minds? Just a guess.

                     

                    The only problem with that original design is that those nifty array elements do not appear to even exist until the grid is actually submitted in a traditional manner. I don't see them available via script - for use in a function call to a remote object submission for example.

                     

                    So my workaround has been to convince the client to either (re)process every data point in the grid back to the database all over again (a non-starter) - or dispense with the fancy-schmancy ajax-esque RO submit and just post the cfform/grid old-school (where we can actually see which data to process).