3.2.0

Cancelling a selection?

First of all, nice work!

My task at hand is to do some verification if the user selects another row, and if the verification fails I will need to cancel that selection, basically revert to the selected row prior to the user click. I tried putting that in the "selectionChanged" function, but it gives me a "stack overflow". Here's my code. Any help would be appreciated!

var bCancelClick=false; //a flag I set in an attempt to avoid infinite loop
function showDetail(src){
if (parent.mainFrame.bDirty){
//this is the verification, basically a flag I put in the other frame
if (!confirm("You have not saved the changes you made. By loading another record you will lose these changes. Do you want to drop your changes and move on to another record?")) {
bCancelClick=true;
return;
}
}
var sid=src.getProperty("row/index")
parent.mainFrame.location="wsheetdetail.cfm?schedule_id=" + sid.toString()
}
function cancelClick(){
if (bCancelClick){
obj.setSelectionIndex(parent.mainFrame.iSID); //this is the index before the click
bCancelClick=false;
}
}
obj.setAction("selectionChanged", cancelClick);
obj.setAction("click", showDetail);
chocobo
January 23,
The action "selectionChanged" is fired after the selection already went to the new row. What you need to do is to cancel "selectRow" action. Here is the code:

// first you need this method which I forgot to add
obj.getAction = function(name){
return this["_" + name + "Action"];
};

// now you can save the original action handler
var defaultAction = obj.getAction("selectRow");

// and define yours
var myAction = function(src){
if(confirm("select another row?")){
defaultAction.call(this, src);
}
else {
alert("action cancelled");
}
}

// assign your action handler
obj.setAction("selectRow", myAction);


In the current version it will work only for mouse selections. I will extend this to keyboard selection in 0.2.5
Alex (ActiveWidgets)
January 25,
Worked like a charm. Thanks a lot!!
Keep up the good work.
Chocobo
January 25,
I have 3 grids and i wanted to make the selection among grids mutually exclusive.
I've used the code as suggested i.e i am using
obj.setProperty("selection/index",-1); on other grids

but there is a problem, when i use Ctrl+Click on multiple grids the code is not working, Can anyone suggest me a solution
sai
June 24,
sai, please check your other thread for this answer. Please try to post new questions to new threads that way everything pertaining to your question can be kept in one place and not scattered among many threads.

http://www.activewidgets.com/javascript.forum.5670.2/mutually-exclusive-selection-on-multiple.html
Jim Hunter
June 24,
sorry for posting it here.. i was over anxious to know the solution
sai
June 24,

This topic is archived.

See also:


Back to support forum