I have a two tables, Questions and Answers. I am wanting to create a cfform that will allow me to easily allow for users to create questions, and then assign answer options to these questions.
Using the cfgrid "edit" functionality, I have created the question-creation side no problem. However, I am running into issues with the "answers" portion. While it is easy to add an answer with the cfgrid, I want to be able to link a cfgrid that has the question title to another cfgrid that displays the current answers that have the selected question's ID. At ASFusion.com, I found a nice example about filtering the results between the grids. Unfortunately, whenever a filter is applied, the edit functionality (insert, delete) of the answer grid stops working, and updating the form passes without any values. A follow-up example of how to do this was posted on ASFusion, but I don't think that it specifically applies to what I am doing, and I do not have the experience or knowledge to modify the actionscript to do what I need it to do. I will post my code below, and I appreciate any help that anyone can offer. <!---Here's the code for updating the database, and it works brilliantly when no records are filtered.---> <cfif isdefined("Form.myGrid.rowstatus.action")> <cfloop index = "CounterA" from = "1" to = #arraylen(Form.myGrid.rowstatus.action)#> <cfif Form.myGrid.rowstatus.action[counterA] is "D"> <cfquery name="DeleteExistingAnswer" datasource="Test"> DELETE FROM Answers WHERE AnswerID=#Form.myGrid.original.AnswerID[CounterA]# </cfquery> <cfelseif Form.myGrid.rowstatus.action[counterA] is "U"> <cfquery name="UpdateExistingAnswer" datasource="Test"> UPDATE Answers SET AnswerText='#Form.myGrid.AnswerText[CounterA]#', QuestionID='#Form.myGrid.QuestionID[CounterA]#', '#testid#' WHERE AnswerID=#Form.myGrid.original.AnswerID[CounterA]# </cfquery> <cfelseif Form.myGrid.rowstatus.action[counterA] is "I"> <cfquery name="InsertNewQuestion" datasource="Test"> INSERT into Answers (AnswerText, QuestionID, TestID) VALUES ( AnswerText='#Form.myGrid.AnswerText[CounterA]#', QuestionID='#Form.myGrid.QuestionID[CounterA]#', '#testid#' ) </cfquery> </cfif> </cfloop> </cfif> <!---Here's the "Answers" portion of my form, with the AS---> <cfformitem type="script"> function applyFilter( term:String, grid:mx.controls.DataGrid, columns:Array ):Void { var filterTerm:String = term.toString().toLowerCase(); if(filterTerm.length > 0) { if(_global.unfilteredData[grid.id] == undefined){ if (_global.unfilteredData == undefined){_global.unfilteredData = {}; } _global.unfilteredData[grid.id] = grid.dataProvider.slice(0); } var filteredData:Array = [];for(var i = 0; i< _global.unfilteredData[grid.id].length; i++) { var item:Object = _global.unfilteredData[grid.id][i]; var added:Boolean = false; for(var j = 0; j< columns.length; j++){ if(!added){ var value:String = item[columns[j]].toString().toLowerCase(); if(value.indexOf(filterTerm) != -1) { filteredData.push(item); added = true; } } else { break; } } } grid.dataProvider = filteredData; } else { if(_global.unfilteredData[grid.id] != undefined) grid.dataProvider = _global.unfilteredData[grid.id]; } } </cfformitem> <cfformgroup type="horizontal"> <cfformgroup type="vbox" width="300"> <cfgrid name="QuestionSelect" query="Test" rowheaders="false" width="250" onchange="applyFilter(QuestionSelect.selectedItem.QuestionText,mygrid,['QuestionText'])"> <cfgridcolumn name="QuestionText" header="Question"> </cfgrid> </cfformgroup> <cfformgroup type="vbox"> <cfgrid name="mygrid" width="550" query="Answer" insert="yes" delete="yes" selectmode="edit" enabled="yes" visible="yes"> <cfgridcolumn name="QuestionID" display="yes"> <cfgridcolumn name="AnswerText" header="Answers"> <cfgridcolumn name="AnswerID" display="no"> <cfgridcolumn name="TestID" display="no"> </cfgrid> </cfformgroup> </cfformgroup> <cfinput type="submit" value="Save" name="saveanswers" > Thanks for your help. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Upgrade to Adobe ColdFusion MX7 Experience Flex 2 & MX7 integration & create powerful cross-platform RIAs http://www.adobe.com/products/coldfusion/flex2/ Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:272271 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4