I would like to do something if a user double-clicks on an object on a form. Since there is no OnDoubleClick event, is there some other way to do this?
Haven’t tested this but what you could do is create a (global) variable, set it to initially zero and let the method that you attach to the onAction event of the button execute when the variable equals 2. In code this would look like:
globals.var += 1; //start adding the value
if (globals.var == 2) { //capture the second click
//execute code;
globals.var = 0; //set the variable to the initial value
}
make sure you do a globals.var = 0 on opening the form.
That doesn’t do it.
What I am looking for is being able to trap a real windows double-click event – not two single clicks. The problem with the two single-clicks is if they press one click, then wait a few seconds or more and press it again, your routine would think it is the second click of a double click.
If it can’t trap a real double-click event then fine, I just want to know.
Yep, that’s an issue… Or not. There is no other way and certainly not on the window itself.
i’d love to see this as well.
what kind of object?
Most objects don’t have really a double click. For example a buttons always will work on a single click
Double clicking in a text area/fields mostly already means something (selecting the word).
The only realy doubleClick event i can think of is on labels..
What I sometimes like to do is allow the user to double-click on either a combo box or its label and popup a form with all of the values that populate the combo box so the user can add, remove and/or edit the combo values.
i was envisioning a summary listing (list view) of records, and a
double click on a line item would, for example, bring
up a detail (record view) screen
You can build a HTML report with an underline link for the detail record. That underline can point to another Servoy method and you can pass in the ID of the parent as a parameter.
As far as DOUBLE CLICK events go - I simulated a double click event the same way that was talked about above - and it works brilliantly!
Cheers,
Bob Cusick
Bob, your suggestion of an HTML underline link is excellent. Thanks.
Regarding your comment about your simulated double-click event: I’m sure it works brilliantly if the user double-clicks on it – just the way you want them to. BUT, if they click once on it, and wait some time, and then click once again – your brilliant double-click event will fire when it shouldn’t.
Nope. Won’t fire unless it’s clicked on within the timeframe. It will just count as a single click and “restart” the clock.
Bob
Then your code must be different than the code above. There is no clock in the code above (at least not that I can see).
Can you share a copy of your code?
Yep, sorry - my code IS different. I have the debug code in there for the “showDialog” steps - is handy if you want to see what’s going on. You also need a global integer variable called “gLastClick”. Here’s the code:
var today = new Date();
var newClick = today.getTime();
if(globals.gLastClick == 0) {
// plugins.dialogs.showInfoDialog( 'One Click', 'Orig Click: ' + globals.gLastClick + '\nNew Click: ' + newClick, 'OK');
globals.gLastClick = newClick;
} else {
// plugins.dialogs.showInfoDialog( 'Two Click', 'Orig Click: ' + globals.gLastClick + '\nNew Click: ' + newClick + '\nDiff: ' + '' +( newClick - globals.gLastClick), 'OK');
if((newClick - globals.gLastClick) > 350) {
globals.gLastClick = newClick
} else {
//was fast enough - YOUR CODE HERE
globals.gLastClick =0;
}
}
NOTE: You can increase or decrease the value of 350 to make the double-click recognize shorter or longer times between clicks.
Hope this helps,
Bob Cusick
Cool Bob.
Thats great.
Thanks!
Bob, great suggestion. I took the liberty to change it a little into a more generic method:
in your method you put:
if (globals.doubleClick()) {
//execute code
}
Now create a global method like this:
/**
* Emulate a doubleClick event
*/
var today = new Date();
var newClick = today.getTime();
if(lastClick == 0) {
lastClick = newClick;
} else {
if((newClick - lastClick) > 300) {
lastClick = newClick;
} else {
lastClick = 0;
return true;
}
}
return false;
REMARK: I don’t use a global declaration for the var lastClick. This can be made a global like in the example of Bob. If you don’t do this you have to set lastClick = 0 on loading the form or solution…
Have fun with it.
Marcel,
GREAT additions!
Thanks for sharing this great improvement!
Cheers,
Bob
To make things worse, I have made an addition. The current procedure does not work as intended if you click on one record and then really fast on another. The current “joint development” doesn’t care which record somebody clicked on, just how fast the click interval was. So with the addition, the method looks like this:
var today = new Date();
var newClick = today.getTime();
var recordID = arguments[0];
if(globals.lastClick == 0)
{
globals.lastClick = newClick;
globals.lastClickID = recordID;
}
else
{
if (((newClick - globals.lastClick) > 600) ||
globals.lastClickID != recordID)
{
globals.lastClick = newClick;
globals.lastClickID = recordID;
}
else
{
globals.lastClick = 0;
return true;
}
}
return false;
and has to be called like
if (globals.doubleClick(recordID)) {
//execute code
}
In short: you need to pass the primary key of the record clicked on and compare it with the last clicked record ID (globals.lastClickID).