-
1. Re: cfgrid (type=flash) - how to capture in-cell keystroke event?
BKBK Nov 12, 2012 6:20 AM (in response to AlHolden)<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 Nov 12, 2012 10:53 AM (in response to BKBK)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 Nov 12, 2012 12:39 PM (in response to AlHolden)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 Nov 13, 2012 1:31 PM (in response to AlHolden)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 Nov 15, 2012 1:24 AM (in response to AlHolden)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 Nov 15, 2012 11:31 AM (in response to BKBK)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).

