Search This Blog

Monday 6 May 2013

Double Click event in LiveCycle Designer forms

Problem

Double Click is often used as a way to select a default option, but none of the controls supplied with Designer support a double click event.

Solution

This solution uses an app.setTimeOut() method in the click event to re-execute the click event in 250ms, if within that time there is another click from the user then it is taken as a double click, otherwise the single click will occur when the click event is re-executed.

Detailed explanation

This code goes in the click event of the control

var clickTime = new Date().getTime() - XFAUtil.getProperty(this, "clickTime");
if (clickTime < 250) //double click time less than 150ms{
    // Double click code goes here

    app.clearTimeOut(app.timeout);
    XFAUtil.deleteProperty(this, "clickTime");
}
else
{
    if (xfa.event.fullText !== "singleClick")
    {
        app.timeout = app.setTimeOut("xfa.event.fullText='singleClick';xfa.resolveNode('"+this.somExpression+"').execEvent('click');",250);
        XFAUtil.setProperty(this, "clickTime", new Date().getTime(), XFAUtil.ContentType.Time);
    }
    else
    {
    // Single click code goes here    }
}


XFAUtil is my script object to store and read values in the <desc> element of a field or the <variables> element of a subform.

At the first click the clickTime will be greater than 250ms (as XFAUtil.getProperty(this, "clickTime") will return a null).  The xfa.event.fullText property will also not equal "singleClick" as this is my flag to say this is a re-executing click and is set as part of the app.setTimeOut().

My first example is a List Picker control, an item can be selected by clicking item then the Select or Unselect button or you can double click an item.



Another example is a Portlet style, an item can be selected by double clicking it or from the context menu which is displayed on a single click.


Download sample, DoubleClick.pdf.

No comments:

Post a Comment